package models

import "fmt"

type Backup struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

func NewBackup(name string) *Backup {
	return &Backup{name, "TestBackup"}
}

func (item *BackupItem) String() string {
	if item == nil {
		return ""
	}
	return fmt.Sprintf("{id:%s,name:%s,description:%s,type:%s,create_timestamp:%s,size:%+v,status:%+v}", item.Id, item.Name, item.Description, item.Type, item.CreateTimestamp, item.Size, item.Status)
}

type BackupItem struct {
	Id              string `json:"id,omitempty"`
	Name            string `json:"name,omitempty"`
	Description     string `json:"description,omitempty"`
	Type            string `json:"type,omitempty"`
	CreateTimestamp string `json:"create_timestamp,omitempty"`
	Size            string `json:"size,omitempty"`
	Status          string `json:"status,omitempty"`
}

type CreateBackupResp struct {
	Id       string `json:"id,omitempty"`
	BackupId string `json:"backup_id,omitempty"`
}

type Restore struct {
	BackupId string        `json:"backup_id"`
	Name     string        `json:"name,omitempty"`
	Config   ClusterConfig `json:"config,omitempty"`
}

type CreateRestoreResp struct {
	Id        string `json:"id"`
	ClusterId string `json:"cluster_id"`
}

type Cluster struct {
	Id     string `json:"id"`
	Name   string `json:"name"`
	Status string `json:"status"`
}

type RestoreTaskpResp struct {
	Id              string  `json:"id,omitempty"`
	CreateTimestamp string  `json:"create_timestamp,omitempty"`
	BackupId        string  `json:"backup_id,omitempty"`
	ClusterId       string  `json:"cluster_id,omitempty"`
	Status          string  `json:"status,omitempty"`
	Cluster         Cluster `json:"cluster,omitempty"`
	ErrorMessage    string  `json:"error_message,omitempty"`
}

type Import struct {
	Name    string      `json:"name,omitempty"`
	Spec    SpecInfo    `json:"spec,omitempty"`
	Options OptionsInfo `json:"options,omitempty"`
}

type OptionsInfo struct {
	PreCreateTables []PreCreateTable `json:"pre_create_tables,omitempty"`
}

type PreCreateTable struct {
	DatabaseName string     `json:"database_name,omitempty"`
	TableName    string     `json:"table_name,omitempty"`
	Schema       SchemaInfo `json:"schema,omitempty"`
}

type SchemaInfo struct {
	ColumnDefinitions []ColumnDefinition `json:"column_definitions,omitempty"`
	PrimaryKeyColumns []string           `json:"primary_key_columns,omitempty"`
}

type ColumnDefinition struct {
	ColumnName string `json:"column_name,omitempty"`
	ColumnType string `json:"column_type,omitempty"`
}

type SpecInfo struct {
	Source SourceInfo `json:"source,omitempty"`
	Target TargetInfo `json:"target,omitempty"`
}

type TargetInfo struct {
	Tables []Table `json:"tables,omitempty"`
}

type Table struct {
	DatabaseName    string `json:"database_name,omitempty"`
	TableName       string `json:"table_name,omitempty"`
	FileNamePattern string `json:"file_name_pattern,omitempty"`
}

type SourceInfo struct {
	TypeData            string                   `json:"type,omitempty"`
	Uri                 string                   `json:"uri,omitempty"`
	AwsAssumeRoleAccess *AwsAssumeRoleAccessInfo `json:"aws_assume_role_access,omitempty"`
	AwsKeyAccess        *AwsKeyAccessInfo        `json:"aws_key_access,omitempty"`
	Format              *FormatInfo              `json:"format,omitempty"`
}

type AwsAssumeRoleAccessInfo struct {
	AssumeRole string `json:"assume_role,omitempty"`
}

type AwsKeyAccessInfo struct {
	AccessKeyId     string `json:"access_key_id,omitempty"`
	SecretAccessKey string `json:"secret_access_key,omitempty"`
}

type FormatInfo struct {
	TypeData  string        `json:"type,omitempty"`
	CsvConfig CsvConfigInfo `json:"csv_config,omitempty"`
}

type CsvConfigInfo struct {
	Delimiter       string `json:"delimiter,omitempty"`
	Quote           string `json:"quote,omitempty"`
	BackslashEscape bool   `json:"backslash_escape,omitempty"`
	HasHeaderRow    bool   `json:"has_header_row,omitempty"`
}

type ImportResp struct {
	Id string `json:"id,omitempty"`
}

type PreviewResp struct {
	TablePreviews []TablePreviews `json:"table_previews,omitempty"`
}

type TablePreviews struct {
	DatabaseName  string     `json:"database_name,omitempty"`
	TableName     string     `json:"table_name,omitempty"`
	SchemaPreview SchemaInfo `json:"schema_preview,omitempty"`
	DataPreview   DataInfo   `json:"data_preview,omitempty"`
}

type DataInfo struct {
	ColumnNames []string `json:"column_names,omitempty"`
	Rows        []Row    `json:"rows,omitempty"`
}

type Row struct {
	Columns []string `json:"columns,omitempty"`
}

type Preview struct {
	Spec           SpecInfo `json:"spec,omitempty"`
	LimitRowsCount int      `json:"limit_rows_count,omitempty"`
}

type RoleInfoResp struct {
	AwsImportRole AwsRole `json:"aws_import_role,omitempty"`
	GcpImportRole GcpRole `json:"gcp_import_role,omitempty"`
}

type AwsRole struct {
	AccountId  string `json:"account_id,omitempty"`
	ExternalId string `json:"external_id,omitempty"`
}

type GcpRole struct {
	AccountId string `json:"account_id,omitempty"`
}

type UploadLocalFile struct {
	LocalFileName string      `json:"local_file_name,omitempty"`
	Payload       PayloadInfo `json:"payload,omitempty"`
}

type PayloadInfo struct {
	TotalSizeBytes string `json:"total_size_bytes,omitempty"`
	Content        string `json:"content,omitempty"`
}

type UploadLocalFileResp struct {
	UploadStubId string `json:"upload_stub_id,omitempty"`
}

type ImportDetail struct {
	Metadata Metadata   `json:"metadata,omitempty"`
	Spec     SpecInfo   `json:"spec,omitempty"`
	Status   StatusInfo `json:"status,omitempty"`
}

type Metadata struct {
	Id              string `json:"id,omitempty"`
	Name            string `json:"name,omitempty"`
	CreateTimestamp string `json:"create_timestamp,omitempty"`
}

type StatusInfo struct {
	Phase                string   `json:"phase,omitempty"`
	ErrorMessage         string   `json:"error_message,omitempty"`
	StartTimestamp       string   `json:"start_timestamp,omitempty"`
	EndTimestamp         string   `json:"end_timestamp,omitempty"`
	Progress             Progress `json:"progress,omitempty"`
	SourceTotalSizeBytes string   `json:"source_total_size_bytes,omitempty"`
}

type Progress struct {
	ImportProgress     int `json:"import_progress,omitempty"`
	ValidationProgress int `json:"validation_progress,omitempty"`
}

type UpdateImport struct {
	Action string `json:"action,omitempty"`
}
