package jira

import (
	"time"
)

type IssueCustomerInfo struct {
	IssueKey    string  `gorm:"type:VARCHAR(255);primary_key;not null"`
	Environment string  `gorm:"type:VARCHAR(255);not null"`
	ClusterID   *string `gorm:"type:VARCHAR(255)"`
	TenantID    *string `gorm:"type:VARCHAR(255)"`
}

func (IssueCustomerInfo) TableName() string {
	return "jira_issue_customer_info"
}

type IssueSnapshot struct {
	Key           string     `gorm:"type:VARCHAR(255);primary_key;not null"`
	ID            string     `gorm:"type:VARCHAR(255);not null"`
	Summary       string     `gorm:"type:VARCHAR(1024);not null"`
	Status        string     `gorm:"type:VARCHAR(255);not null"`
	Priority      string     `gorm:"type:VARCHAR(255);not null"`
	CreatedAt     time.Time  `gorm:"type:TIMESTAMP;not null"`
	ResolvedAt    *time.Time `gorm:"type:TIMESTAMP"`
	AssigneeEmail *string    `gorm:"type:VARCHAR(255)"`
	ReporterEmail *string    `gorm:"type:VARCHAR(255)"`
	ProjectKey    string     `gorm:"type:VARCHAR(255);not null"`
	Components    []string   `gorm:"type:JSON;serializer:json"`

	// Associations
	CustomerInfo *IssueCustomerInfo `gorm:"foreignKey:IssueKey;references:Key"`
}

func (IssueSnapshot) TableName() string {
	return "jira_issue_snapshots"
}

type Issue struct {
	Key                 string     `gorm:"type:VARCHAR(255);primary_key;not null"`
	StoredAt            time.Time  `gorm:"stored_at;type:TIMESTAMP;not null;<-:create;autoCreateTime"` // create and read only
	CreatedAt           *time.Time `gorm:"created_at;type:TIMESTAMP"`
	HaveTriage          bool       `gorm:"type:BOOLEAN;not null;default:false"`
	HaveTimelineSummary bool       `gorm:"type:BOOLEAN;not null;default:false"`

	// Associations
	Snapshot *IssueSnapshot `gorm:"foreignKey:Key;references:Key"`
}

func (Issue) TableName() string {
	return "jira_issues"
}

type IssueTriageTags struct {
	Scene          *string `gorm:"type:VARCHAR(255)"`
	RootCause      *string `gorm:"type:VARCHAR(255)"`
	Preventability *string `gorm:"type:VARCHAR(255)"`
	Solution       *string `gorm:"type:VARCHAR(255)"`
}

type IssueTriage struct {
	Key          string          `gorm:"type:VARCHAR(255);primary_key;not null"`
	CreatedAt    time.Time       `gorm:"created_at;type:TIMESTAMP;not null;<-:create"` // create and read only
	UpdatedAt    *time.Time      `gorm:"updated_at;type:TIMESTAMP"`
	BriefSummary *string         `gorm:"type:TEXT"`
	Tags         IssueTriageTags `gorm:"embedded;embeddedPrefix:tag_"`
}

func (IssueTriage) TableName() string {
	return "jira_issue_triages"
}
