use std::collections::BTreeMap;
use std::sync::Arc;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use fakecloud_core::multi_account::{AccountState, MultiAccountState};
pub const CODECONNECTIONS_SNAPSHOT_SCHEMA_VERSION: u32 = 1;
pub type TagMap = BTreeMap<String, String>;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionRecord {
pub connection_arn: String,
pub connection_name: String,
#[serde(default)]
pub provider_type: Option<String>,
pub owner_account_id: String,
pub connection_status: String,
#[serde(default)]
pub host_arn: Option<String>,
#[serde(default)]
pub tags: TagMap,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HostRecord {
pub host_arn: String,
pub name: String,
pub provider_type: String,
pub provider_endpoint: String,
pub status: String,
#[serde(default)]
pub vpc_configuration: Option<Value>,
#[serde(default)]
pub tags: TagMap,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RepositoryLinkRecord {
pub repository_link_id: String,
pub repository_link_arn: String,
pub connection_arn: String,
pub owner_id: String,
pub repository_name: String,
pub provider_type: String,
#[serde(default)]
pub encryption_key_arn: Option<String>,
#[serde(default)]
pub tags: TagMap,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncConfigurationRecord {
pub branch: String,
#[serde(default)]
pub config_file: Option<String>,
pub owner_id: String,
pub provider_type: String,
pub repository_link_id: String,
pub repository_name: String,
pub resource_name: String,
pub role_arn: String,
pub sync_type: String,
#[serde(default)]
pub publish_deployment_status: Option<String>,
#[serde(default)]
pub trigger_resource_update_on: Option<String>,
#[serde(default)]
pub pull_request_comment: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CodeConnectionsState {
#[serde(default)]
pub connections: BTreeMap<String, ConnectionRecord>,
#[serde(default)]
pub hosts: BTreeMap<String, HostRecord>,
#[serde(default)]
pub repository_links: BTreeMap<String, RepositoryLinkRecord>,
#[serde(default)]
pub sync_configurations: BTreeMap<String, SyncConfigurationRecord>,
}
impl AccountState for CodeConnectionsState {
fn new_for_account(_account_id: &str, _region: &str, _endpoint: &str) -> Self {
Self::default()
}
}
pub type SharedCodeConnectionsState = Arc<RwLock<MultiAccountState<CodeConnectionsState>>>;
#[derive(Debug, Serialize, Deserialize)]
pub struct CodeConnectionsSnapshot {
pub schema_version: u32,
pub accounts: MultiAccountState<CodeConnectionsState>,
}
pub fn skey(sync_type: &str, resource_name: &str) -> String {
format!("{sync_type}\u{1}{resource_name}")
}