package model

import (
	"gorm.io/datatypes"
	"gorm.io/gorm"
)

// AssetAllocationRecord 资产分配记录模型
// 记录卡/设备在平台和代理商之间的流转历史
type AssetAllocationRecord struct {
	gorm.Model
	BaseModel       `gorm:"embedded"`
	AllocationNo    string         `gorm:"column:allocation_no;type:varchar(50);index;not null;comment:分配单号（同批次相同）" json:"allocation_no"`
	AllocationType  string         `gorm:"column:allocation_type;type:varchar(20);index;not null;comment:分配类型 allocate=分配 recall=回收" json:"allocation_type"`
	AssetType       string         `gorm:"column:asset_type;type:varchar(20);index;not null;comment:资产类型 iot_card=物联网卡 device=设备" json:"asset_type"`
	AssetID         uint           `gorm:"column:asset_id;index;not null;comment:资产ID" json:"asset_id"`
	AssetIdentifier string         `gorm:"column:asset_identifier;type:varchar(50);not null;comment:资产标识符（ICCID或设备号）" json:"asset_identifier"`
	FromOwnerType   string         `gorm:"column:from_owner_type;type:varchar(20);comment:来源所有者类型" json:"from_owner_type"`
	FromOwnerID     *uint          `gorm:"column:from_owner_id;comment:来源所有者ID" json:"from_owner_id,omitempty"`
	ToOwnerType     string         `gorm:"column:to_owner_type;type:varchar(20);not null;comment:目标所有者类型" json:"to_owner_type"`
	ToOwnerID       uint           `gorm:"column:to_owner_id;not null;comment:目标所有者ID" json:"to_owner_id"`
	RelatedDeviceID *uint          `gorm:"column:related_device_id;comment:关联设备ID" json:"related_device_id,omitempty"`
	RelatedCardIDs  datatypes.JSON `gorm:"column:related_card_ids;type:jsonb;comment:关联卡ID列表" json:"related_card_ids,omitempty"`
	OperatorID      uint           `gorm:"column:operator_id;not null;comment:操作人ID" json:"operator_id"`
	Remark          string         `gorm:"column:remark;type:text;comment:备注" json:"remark"`
}

func (AssetAllocationRecord) TableName() string {
	return "tb_asset_allocation_record"
}
