package model

import (
	"time"

	"gorm.io/gorm"
)

// EnterpriseCardAuthorization 企业卡授权模型
// 注意：不使用 BaseModel，因为已有 AuthorizedBy/RevokedBy 字段
type EnterpriseCardAuthorization struct {
	ID             uint           `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	CreatedAt      time.Time      `gorm:"column:created_at" json:"created_at"`
	UpdatedAt      time.Time      `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt      gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
	EnterpriseID   uint           `gorm:"column:enterprise_id;not null;comment:被授权企业ID" json:"enterprise_id"`
	CardID         uint           `gorm:"column:card_id;not null;comment:被授权卡ID" json:"card_id"`
	AuthorizedBy   uint           `gorm:"column:authorized_by;not null;comment:授权人账号ID" json:"authorized_by"`
	AuthorizedAt   time.Time      `gorm:"column:authorized_at;not null;default:CURRENT_TIMESTAMP;comment:授权时间" json:"authorized_at"`
	AuthorizerType int            `gorm:"column:authorizer_type;not null;comment:授权人类型：2=平台用户 3=代理账号" json:"authorizer_type"`
	RevokedBy      *uint          `gorm:"column:revoked_by;comment:回收人账号ID" json:"revoked_by"`
	RevokedAt      *time.Time     `gorm:"column:revoked_at;comment:回收时间" json:"revoked_at"`
	Remark         string         `gorm:"column:remark;type:varchar(500);default:'';comment:授权备注" json:"remark"`
	DeviceAuthID   *uint          `gorm:"column:device_auth_id;comment:关联的设备授权ID" json:"device_auth_id"`
}

func (EnterpriseCardAuthorization) TableName() string {
	return "tb_enterprise_card_authorization"
}
