package model

import "time"

// ApprovalDecisionDelivery 是标准审批决策交给业务消费者的幂等处理事实。
type ApprovalDecisionDelivery struct {
	ID             uint       `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	InstanceID     uint       `gorm:"column:instance_id;not null;uniqueIndex:uq_approval_decision_delivery,priority:1" json:"instance_id"`
	Decision       string     `gorm:"column:decision;type:varchar(32);not null;uniqueIndex:uq_approval_decision_delivery,priority:2" json:"decision"`
	EventID        string     `gorm:"column:event_id;type:varchar(64);not null;uniqueIndex" json:"event_id"`
	Status         int        `gorm:"column:status;type:int;not null;default:0;index:idx_approval_decision_delivery_claim,priority:1" json:"status"`
	RetryCount     int        `gorm:"column:retry_count;type:int;not null;default:0" json:"retry_count"`
	LeaseOwner     *string    `gorm:"column:lease_owner;type:varchar(100)" json:"lease_owner,omitempty"`
	LeaseExpiresAt *time.Time `gorm:"column:lease_expires_at;type:timestamptz;index:idx_approval_decision_delivery_claim,priority:2" json:"lease_expires_at,omitempty"`
	LastError      string     `gorm:"column:last_error;type:varchar(500);not null;default:''" json:"last_error,omitempty"`
	ProcessedAt    *time.Time `gorm:"column:processed_at;type:timestamptz" json:"processed_at,omitempty"`
	CreatedAt      time.Time  `gorm:"column:created_at;type:timestamptz;not null;autoCreateTime" json:"created_at"`
	UpdatedAt      time.Time  `gorm:"column:updated_at;type:timestamptz;not null;autoUpdateTime" json:"updated_at"`
}

// TableName 返回审批决策投递表名。
func (ApprovalDecisionDelivery) TableName() string {
	return "tb_approval_decision_delivery"
}
