package model

import (
	"time"

	"gorm.io/gorm"
)

// OrderPackageInvalidateTask 订单套餐批量失效任务模型
type OrderPackageInvalidateTask struct {
	ID           uint             `gorm:"column:id;primaryKey" json:"id"`
	TaskNo       string           `gorm:"column:task_no;type:varchar(50);uniqueIndex;not null;comment:任务编号" json:"task_no"`
	Status       int              `gorm:"column:status;type:int;not null;default:1;comment:任务状态 (1:待处理, 2:处理中, 3:已完成, 4:失败)" json:"status"`
	TotalCount   int              `gorm:"column:total_count;type:int;not null;default:0;comment:总行数" json:"total_count"`
	SuccessCount int              `gorm:"column:success_count;type:int;not null;default:0;comment:成功数" json:"success_count"`
	FailCount    int              `gorm:"column:fail_count;type:int;not null;default:0;comment:失败数" json:"fail_count"`
	FailedItems  ImportResultItems `gorm:"column:failed_items;type:jsonb;not null;default:'[]';comment:失败记录详情(jsonb)" json:"failed_items"`
	FileName     string           `gorm:"column:file_name;type:varchar(255);not null;default:'';comment:原始文件名" json:"file_name"`
	StorageKey   string           `gorm:"column:storage_key;type:varchar(500);not null;default:'';comment:CSV 文件对象存储路径" json:"storage_key"`
	VoucherKeys  StringJSONBArray `gorm:"column:voucher_keys;type:jsonb;not null;default:'[]';comment:支付凭证对象存储Key列表（最多5个）" json:"voucher_keys"`
	Remark       string           `gorm:"column:remark;type:text;not null;default:'';comment:运营备注（创建时填写，只读）" json:"remark"`
	CreatorName  string           `gorm:"column:creator_name;type:varchar(100);not null;default:'';comment:操作人姓名快照" json:"creator_name"`
	ErrorMessage string           `gorm:"column:error_message;type:text;not null;default:'';comment:任务级错误信息" json:"error_message"`
	StartedAt    *time.Time       `gorm:"column:started_at;comment:开始处理时间" json:"started_at"`
	CompletedAt  *time.Time       `gorm:"column:completed_at;comment:完成时间" json:"completed_at"`
	Creator      uint             `gorm:"column:creator;not null;default:0;comment:创建人ID" json:"creator"`
	Updater      uint             `gorm:"column:updater;not null;default:0;comment:更新人ID" json:"updater"`
	CreatedAt    time.Time        `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt    time.Time        `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
	DeletedAt    gorm.DeletedAt   `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
}

// TableName 指定表名
func (OrderPackageInvalidateTask) TableName() string {
	return "tb_order_package_invalidate_task"
}
