package models

import "time"

const (
	RelationStatusActive  = "active"
	RelationStatusRemoved = "removed"
)

type TiDBCloudOrg struct {
	ID                     string     `gorm:"column:id;type:varchar(64);primaryKey"`
	Name                   string     `gorm:"column:name;type:varchar(255);not null"`
	Status                 string     `gorm:"column:status;type:varchar(64);index"`
	SupportPlan            string     `gorm:"column:support_plan;type:varchar(64);index"`
	Plan                   string     `gorm:"column:plan;type:varchar(64);index"`
	JSMOrgID               *string    `gorm:"column:jsm_org_id;type:varchar(64);index"`
	MSPOrgID               *string    `gorm:"column:msp_org_id;type:varchar(64);index"`
	MSPRelationCheckedAt   *time.Time `gorm:"column:msp_relation_checked_at;type:TIMESTAMP;index"`
	MSPNotificationEnabled bool       `gorm:"column:msp_notification_enabled;type:tinyint(1);not null;default:0"`
	BizRegion              string     `gorm:"column:biz_region;type:varchar(64);index"`
	TimeZone               string     `gorm:"column:time_zone;type:varchar(64)"`
	CreatedAt              time.Time  `gorm:"column:created_at;type:TIMESTAMP;autoCreateTime:milli"`
	UpdatedAt              time.Time  `gorm:"column:updated_at;type:TIMESTAMP;autoUpdateTime:milli"`
}

func (TiDBCloudOrg) TableName() string {
	return "tidbcloud_orgs"
}

type TiDBCloudUser struct {
	ID                 string    `gorm:"column:id;type:varchar(64);primaryKey"`
	Email              string    `gorm:"column:email;type:varchar(320);uniqueIndex;not null"`
	FirstName          *string   `gorm:"column:first_name;type:varchar(128)"`
	LastName           *string   `gorm:"column:last_name;type:varchar(128)"`
	AtlassianAccountID *string   `gorm:"column:atlassian_account_id;type:varchar(128);index"`
	CreatedAt          time.Time `gorm:"column:created_at;type:TIMESTAMP;autoCreateTime:milli"`
	UpdatedAt          time.Time `gorm:"column:updated_at;type:TIMESTAMP;autoUpdateTime:milli"`
}

func (TiDBCloudUser) TableName() string {
	return "tidbcloud_users"
}

type TiDBCloudLake struct {
	ID          string    `gorm:"column:id;type:varchar(64);primaryKey"`
	Name        string    `gorm:"column:name;type:varchar(255);not null"`
	Tier        string    `gorm:"column:tier;type:varchar(64)"`
	SupportPlan string    `gorm:"column:support_plan;type:varchar(64);index"`
	OrgID       string    `gorm:"column:org_id;type:varchar(64);index"`
	Status      string    `gorm:"column:status;type:varchar(64);index"`
	CreatedAt   time.Time `gorm:"column:created_at;type:TIMESTAMP;autoCreateTime:milli"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:TIMESTAMP;autoUpdateTime:milli"`
}

func (TiDBCloudLake) TableName() string {
	return "tidbcloud_lakes"
}

type TiDBCloudOrgMembership struct {
	OrgID     string    `gorm:"column:org_id;type:varchar(64);uniqueIndex:uniq_org_user;index"`
	UserID    string    `gorm:"column:user_id;type:varchar(64);uniqueIndex:uniq_org_user;index"`
	Status    string    `gorm:"column:status;type:varchar(32);index"`
	CreatedAt time.Time `gorm:"column:created_at;type:TIMESTAMP;autoCreateTime:milli"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:TIMESTAMP;autoUpdateTime:milli"`
}

func (TiDBCloudOrgMembership) TableName() string {
	return "tidbcloud_org_memberships"
}

type TiDBCloudLakeMembership struct {
	LakeID    string    `gorm:"column:lake_id;type:varchar(64);uniqueIndex:uniq_lake_user;index"`
	UserID    string    `gorm:"column:user_id;type:varchar(64);uniqueIndex:uniq_lake_user;index"`
	Status    string    `gorm:"column:status;type:varchar(32);index"`
	CreatedAt time.Time `gorm:"column:created_at;type:TIMESTAMP;autoCreateTime:milli"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:TIMESTAMP;autoUpdateTime:milli"`
}

func (TiDBCloudLakeMembership) TableName() string {
	return "tidbcloud_lake_memberships"
}

type TechnicalRoleOrgWhitelist struct {
	OrgID     string    `gorm:"column:org_id;type:varchar(64);primaryKey"`
	Reason    string    `gorm:"column:reason;type:varchar(255);not null;default:''"`
	CreatedAt time.Time `gorm:"column:created_at;type:TIMESTAMP;autoCreateTime:milli"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:TIMESTAMP;autoUpdateTime:milli"`
}

func (TechnicalRoleOrgWhitelist) TableName() string {
	return "technical_role_org_whitelists"
}
