package kernelimage

import (
	"time"

	"github.com/tidbcloud/devops/models/base"
)

type Release struct {
	base.Updatable

	ArtifactUID                 string     `gorm:"type:VARCHAR(64);not null;uniqueIndex:uk_kernel_image_release_artifact_uid"`
	LocalDevOpsEnv              string     `gorm:"type:VARCHAR(16);not null;index:idx_kernel_image_release_env"`
	Version                     string     `gorm:"type:VARCHAR(128);not null;index:idx_kernel_image_release_repository_version,priority:2"`
	Repo                        string     `gorm:"type:VARCHAR(255);not null;index:idx_kernel_image_release_repo_commit,priority:1"`
	Branch                      string     `gorm:"type:VARCHAR(255);not null"`
	CommitSHA                   string     `gorm:"type:CHAR(40);not null;index:idx_kernel_image_release_repo_commit,priority:2;uniqueIndex:uk_kernel_image_release_source_tag_commit,priority:3"`
	GitTag                      string     `gorm:"type:VARCHAR(128);not null"`
	SourceRepository            string     `gorm:"type:VARCHAR(512);not null;uniqueIndex:uk_kernel_image_release_source_tag_commit,priority:1;index:idx_kernel_image_release_repository_version,priority:1"`
	SourceTag                   string     `gorm:"type:VARCHAR(128);not null;uniqueIndex:uk_kernel_image_release_source_tag_commit,priority:2"`
	SourceDigest                string     `gorm:"type:VARCHAR(128);not null"`
	Status                      string     `gorm:"type:VARCHAR(32);not null;index:idx_kernel_image_release_selection,priority:1"`
	Masked                      bool       `gorm:"not null;default:false;index:idx_kernel_image_release_selection,priority:2"`
	MaskReason                  string     `gorm:"type:TEXT"`
	SourceApplicant             string     `gorm:"type:VARCHAR(255);not null"`
	SourceReleaseID             string     `gorm:"type:VARCHAR(64)"`
	SourceChangeID              string     `gorm:"type:VARCHAR(64)"`
	DeliveryOperationInstanceID *base.ID   `gorm:"index:idx_kernel_image_release_delivery_operation"`
	FormalDeliveryUID           string     `gorm:"type:VARCHAR(64);not null;uniqueIndex:uk_kernel_image_release_formal_delivery_uid"`
	DeliveryBatchUID            string     `gorm:"type:VARCHAR(64);not null;default:'';index:idx_kernel_image_release_delivery_batch"`
	DeliveryTargetImages        []byte     `gorm:"type:JSON"`
	AvailabilityStatus          string     `gorm:"type:VARCHAR(32);not null;default:'UNKNOWN';index:idx_kernel_image_release_availability"`
	AvailabilitySnapshot        []byte     `gorm:"type:JSON"`
	AvailabilityCheckUID        string     `gorm:"type:VARCHAR(64)"`
	AvailabilityCheckStartedAt  *time.Time `gorm:"type:TIMESTAMP"`
	AvailabilityCheckedAt       *time.Time `gorm:"type:TIMESTAMP"`
	AvailabilityLastError       string     `gorm:"type:TEXT"`
	LastErrorCode               string     `gorm:"type:VARCHAR(128)"`
	LastErrorMessage            string     `gorm:"type:TEXT"`
	BuildFinishedAt             *time.Time `gorm:"type:TIMESTAMP"`
	AvailableAt                 *time.Time `gorm:"type:TIMESTAMP"`
}

func (Release) TableName() string {
	return "kernel_image_releases"
}
