package model

import (
	"gorm.io/gorm"
)

// ShopSeriesAllocation 店铺套餐系列分配模型
// 记录上级店铺为下级店铺分配的套餐系列,包含基础返佣配置和梯度返佣开关
// 分配者只能分配自己已被分配的套餐系列,且只能分配给直属下级
type ShopSeriesAllocation struct {
	gorm.Model
	BaseModel           `gorm:"embedded"`
	ShopID              uint   `gorm:"column:shop_id;index;not null;comment:被分配的店铺ID" json:"shop_id"`
	SeriesID            uint   `gorm:"column:series_id;index;not null;comment:套餐系列ID" json:"series_id"`
	AllocatorShopID     uint   `gorm:"column:allocator_shop_id;index;not null;comment:分配者店铺ID(上级)" json:"allocator_shop_id"`
	BaseCommissionMode  string `gorm:"column:base_commission_mode;type:varchar(20);not null;default:percent;comment:基础返佣模式 fixed-固定金额 percent-百分比" json:"base_commission_mode"`
	BaseCommissionValue int64  `gorm:"column:base_commission_value;type:bigint;not null;default:0;comment:基础返佣值(分或千分比,如200=20%)" json:"base_commission_value"`

	// 一次性佣金配置
	EnableOneTimeCommission    bool   `gorm:"column:enable_one_time_commission;type:boolean;not null;default:false;comment:是否启用一次性佣金" json:"enable_one_time_commission"`
	OneTimeCommissionType      string `gorm:"column:one_time_commission_type;type:varchar(20);comment:一次性佣金类型 fixed-固定 tiered-梯度" json:"one_time_commission_type"`
	OneTimeCommissionTrigger   string `gorm:"column:one_time_commission_trigger;type:varchar(30);comment:触发条件 single_recharge-单次充值 accumulated_recharge-累计充值" json:"one_time_commission_trigger"`
	OneTimeCommissionThreshold int64  `gorm:"column:one_time_commission_threshold;type:bigint;default:0;comment:最低阈值(分)" json:"one_time_commission_threshold"`
	OneTimeCommissionMode      string `gorm:"column:one_time_commission_mode;type:varchar(20);comment:返佣模式 fixed-固定金额 percent-百分比" json:"one_time_commission_mode"`
	OneTimeCommissionValue     int64  `gorm:"column:one_time_commission_value;type:bigint;default:0;comment:佣金金额(分)或比例(千分比)" json:"one_time_commission_value"`

	// 强充配置
	EnableForceRecharge      bool  `gorm:"column:enable_force_recharge;type:boolean;default:false;comment:是否启用强充(累计充值时可选)" json:"enable_force_recharge"`
	ForceRechargeAmount      int64 `gorm:"column:force_recharge_amount;type:bigint;default:0;comment:强充金额(分,0表示使用阈值金额)" json:"force_recharge_amount"`
	ForceRechargeTriggerType int   `gorm:"column:force_recharge_trigger_type;type:int;default:2;comment:强充触发类型(1:单次充值, 2:累计充值)" json:"force_recharge_trigger_type"`

	Status int `gorm:"column:status;type:int;default:1;not null;comment:状态 1-启用 2-禁用" json:"status"`
}

// TableName 指定表名
func (ShopSeriesAllocation) TableName() string {
	return "tb_shop_series_allocation"
}

// 返佣模式常量
const (
	// CommissionModeFixed 固定金额返佣
	CommissionModeFixed = "fixed"
	// CommissionModePercent 百分比返佣(千分比)
	CommissionModePercent = "percent"
)

// 一次性佣金类型常量
const (
	// OneTimeCommissionTypeFixed 固定一次性佣金
	OneTimeCommissionTypeFixed = "fixed"
	// OneTimeCommissionTypeTiered 梯度一次性佣金
	OneTimeCommissionTypeTiered = "tiered"
)

// 一次性佣金触发类型常量
const (
	// OneTimeCommissionTriggerSingleRecharge 单次充值触发
	OneTimeCommissionTriggerSingleRecharge = "single_recharge"
	// OneTimeCommissionTriggerAccumulatedRecharge 累计充值触发
	OneTimeCommissionTriggerAccumulatedRecharge = "accumulated_recharge"
)
