package dto

// CreatePackageRequest 创建套餐请求
type CreatePackageRequest struct {
	PackageCode          string  `json:"package_code" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" description:"套餐编码"`
	PackageName          string  `json:"package_name" validate:"required,min=1,max=255" required:"true" minLength:"1" maxLength:"255" description:"套餐名称"`
	SeriesID             *uint   `json:"series_id" validate:"omitempty" description:"套餐系列ID"`
	PackageType          string  `json:"package_type" validate:"required,oneof=formal addon" required:"true" description:"套餐类型 (formal:正式套餐, addon:附加套餐)"`
	IsGift               bool    `json:"is_gift" description:"是否赠送套餐"`
	DurationMonths       int     `json:"duration_months" validate:"required,min=1,max=120" required:"true" minimum:"1" maximum:"120" description:"套餐时长(月数)"`
	RealDataMB           *int64  `json:"real_data_mb" validate:"omitempty,min=0" minimum:"0" description:"真流量额度(MB)"`
	VirtualDataMB        *int64  `json:"virtual_data_mb" validate:"omitempty,min=0" minimum:"0" description:"虚流量额度(MB)"`
	EnableVirtualData    bool    `json:"enable_virtual_data" description:"是否启用虚流量"`
	SuggestedRetailPrice *int64  `json:"suggested_retail_price" validate:"omitempty,min=0" minimum:"0" description:"建议售价原始值(分，普通可售套餐留空表示未配置，赠送套餐必须显式为0)"`
	CostPrice            int64   `json:"cost_price" validate:"required,min=0" required:"true" minimum:"0" description:"成本价(分)"`
	CalendarType         *string `json:"calendar_type" validate:"omitempty,oneof=natural_month by_day" description:"套餐周期类型 (natural_month:自然月, by_day:按天)"`
	DurationDays         *int    `json:"duration_days" validate:"omitempty,min=1,max=3650" minimum:"1" maximum:"3650" description:"套餐天数(calendar_type=by_day时必填)"`
	DataResetCycle       *string `json:"data_reset_cycle" validate:"omitempty,oneof=daily monthly yearly none" description:"流量重置周期 (daily:每日, monthly:每月, yearly:每年, none:不重置)"`
	ExpiryBase           string  `json:"expiry_base" validate:"omitempty,oneof=from_activation from_purchase" description:"到期时间基准 (from_activation:实名激活时起算, from_purchase:购买时起算)" example:"from_activation"`
}

// UpdatePackageRequest 更新套餐请求
type UpdatePackageRequest struct {
	PackageName          *string `json:"package_name" validate:"omitempty,min=1,max=255" minLength:"1" maxLength:"255" description:"套餐名称"`
	SeriesID             *uint   `json:"series_id" validate:"omitempty" description:"套餐系列ID"`
	PackageType          *string `json:"package_type" validate:"omitempty,oneof=formal addon" description:"套餐类型 (formal:正式套餐, addon:附加套餐)"`
	IsGift               *bool   `json:"is_gift" description:"是否赠送套餐"`
	DurationMonths       *int    `json:"duration_months" validate:"omitempty,min=1,max=120" minimum:"1" maximum:"120" description:"套餐时长(月数)"`
	RealDataMB           *int64  `json:"real_data_mb" validate:"omitempty,min=0" minimum:"0" description:"真流量额度(MB)"`
	VirtualDataMB        *int64  `json:"virtual_data_mb" validate:"omitempty,min=0" minimum:"0" description:"虚流量额度(MB)"`
	EnableVirtualData    *bool   `json:"enable_virtual_data" description:"是否启用虚流量"`
	SuggestedRetailPrice *int64  `json:"suggested_retail_price" validate:"omitempty,min=0" minimum:"0" description:"建议售价原始值(分，普通可售套餐留空表示未配置，赠送套餐必须显式为0)"`
	ClearSuggestedRetailPrice bool `json:"clear_suggested_retail_price" description:"是否清空建议售价并恢复为未配置状态"`
	CostPrice            *int64  `json:"cost_price" validate:"omitempty,min=0" minimum:"0" description:"成本价(分)"`
	CalendarType         *string `json:"calendar_type" validate:"omitempty,oneof=natural_month by_day" description:"套餐周期类型 (natural_month:自然月, by_day:按天)"`
	DurationDays         *int    `json:"duration_days" validate:"omitempty,min=1,max=3650" minimum:"1" maximum:"3650" description:"套餐天数(calendar_type=by_day时必填)"`
	DataResetCycle       *string `json:"data_reset_cycle" validate:"omitempty,oneof=daily monthly yearly none" description:"流量重置周期 (daily:每日, monthly:每月, yearly:每年, none:不重置)"`
	ExpiryBase           *string `json:"expiry_base" validate:"omitempty,oneof=from_activation from_purchase" description:"到期时间基准 (from_activation:实名激活时起算, from_purchase:购买时起算)"`
}

// PackageListRequest 套餐列表请求
type PackageListRequest struct {
	Page        int     `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
	PageSize    int     `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
	PackageName *string `json:"package_name" query:"package_name" validate:"omitempty,max=255" maxLength:"255" description:"套餐名称（模糊搜索）"`
	SeriesID    *uint   `json:"series_id" query:"series_id" validate:"omitempty" description:"套餐系列ID"`
	Status      *int    `json:"status" query:"status" validate:"omitempty,oneof=0 1" description:"状态 (0:禁用, 1:启用)"`
	ShelfStatus *int    `json:"shelf_status" query:"shelf_status" validate:"omitempty,oneof=1 2" description:"上架状态 (1:上架, 2:下架)"`
	PackageType *string `json:"package_type" query:"package_type" validate:"omitempty,oneof=formal addon" description:"套餐类型 (formal:正式套餐, addon:附加套餐)"`
}

// UpdatePackageStatusRequest 更新套餐状态请求
type UpdatePackageStatusRequest struct {
	Status int `json:"status" validate:"required,oneof=0 1" required:"true" description:"状态 (0:禁用, 1:启用)"`
}

// UpdatePackageShelfStatusRequest 更新套餐上架状态请求
type UpdatePackageShelfStatusRequest struct {
	ShelfStatus int `json:"shelf_status" validate:"required,oneof=1 2" required:"true" description:"上架状态 (1:上架, 2:下架)"`
}

// UpdateRetailPriceRequest 更新零售价请求
type UpdateRetailPriceRequest struct {
	RetailPrice int64 `json:"retail_price" validate:"required,min=0" required:"true" minimum:"0" description:"零售价原始值（分，普通可售套餐不允许显式0）"`
}

// CommissionTierInfo 返佣梯度信息
type CommissionTierInfo struct {
	CurrentRate   string `json:"current_rate" description:"当前返佣比例"`
	NextThreshold *int64 `json:"next_threshold,omitempty" description:"下一档位阈值"`
	NextRate      string `json:"next_rate,omitempty" description:"下一档位返佣比例"`
}

// PackageResponse 套餐响应
type PackageResponse struct {
	ID                      uint                `json:"id" description:"套餐ID"`
	PackageCode             string              `json:"package_code" description:"套餐编码"`
	PackageName             string              `json:"package_name" description:"套餐名称"`
	SeriesID                *uint               `json:"series_id" description:"套餐系列ID"`
	SeriesName              *string             `json:"series_name" description:"套餐系列名称"`
	PackageType             string              `json:"package_type" description:"套餐类型 (formal:正式套餐, addon:附加套餐)"`
	IsGift                  bool                `json:"is_gift" description:"是否赠送套餐"`
	DurationMonths          int                 `json:"duration_months" description:"套餐时长(月数)"`
	RealDataMB              int64               `json:"real_data_mb" description:"真流量额度(MB)"`
	VirtualDataMB           int64               `json:"virtual_data_mb" description:"虚流量额度(MB)"`
	EnableVirtualData       bool                `json:"enable_virtual_data" description:"是否启用虚流量"`
	VirtualRatio            float64             `json:"virtual_ratio" description:"虚流量比例(real_data_mb/virtual_data_mb)，启用虚流量时计算，否则为1.0"`
	SuggestedRetailPrice    *int64              `json:"suggested_retail_price,omitempty" description:"建议售价原始值(分，未配置时为空)"`
	PriceConfigStatus       int                 `json:"price_config_status" description:"价格配置状态 (0:未配置, 1:赠送0价, 2:已配置非0)"`
	PriceConfigStatusName   string              `json:"price_config_status_name" description:"价格配置状态名称（中文）"`
	CostPrice               int64               `json:"cost_price" description:"成本价(分)"`
	OneTimeCommissionAmount *int64              `json:"one_time_commission_amount,omitempty" description:"一次性佣金金额（分，代理视角）"`
	Status                  int                 `json:"status" description:"状态 (0:禁用, 1:启用)"`
	StatusName              string              `json:"status_name" description:"状态名称（中文）"`
	ShelfStatus             int                 `json:"shelf_status" description:"上架状态 (1:上架, 2:下架)"`
	ShelfStatusName         string              `json:"shelf_status_name" description:"上架状态名称（中文）"`
	CreatedAt               string              `json:"created_at" description:"创建时间"`
	UpdatedAt               string              `json:"updated_at" description:"更新时间"`
	RetailPrice             *int64              `json:"retail_price,omitempty" description:"代理零售价原始值（分，仅代理用户可见，未配置时为空）"`
	RetailPriceConfigStatus *int                `json:"retail_price_config_status,omitempty" description:"代理零售价配置状态 (0:未配置, 1:赠送0价, 2:已配置非0)"`
	EffectiveRetailPrice    *int64              `json:"effective_retail_price,omitempty" description:"生效零售价（分，仅销售链路展示使用）"`
	ProfitMargin            *int64              `json:"profit_margin,omitempty" description:"利润空间（分，仅代理用户可见）"`
	CurrentCommissionRate   string              `json:"current_commission_rate,omitempty" description:"当前返佣比例（仅代理用户可见）"`
	TierInfo                *CommissionTierInfo `json:"tier_info,omitempty" description:"梯度返佣信息（仅代理用户可见）"`
	CalendarType            string              `json:"calendar_type" description:"套餐周期类型 (natural_month:自然月, by_day:按天)"`
	DurationDays            *int                `json:"duration_days,omitempty" description:"套餐天数(calendar_type=by_day时有值)"`
	DataResetCycle          string              `json:"data_reset_cycle" description:"流量重置周期 (daily:每日, monthly:每月, yearly:每年, none:不重置)"`
	ExpiryBase              string              `json:"expiry_base" description:"到期时间基准 (from_activation:实名激活时起算, from_purchase:购买时起算)"`
	DefaultExpiryBase       string              `json:"default_expiry_base" description:"套餐默认生效条件 (from_activation:实名激活时生效, from_purchase:购买即生效)"`
	DefaultExpiryBaseName   string              `json:"default_expiry_base_name" description:"套餐默认生效条件名称（中文）"`
	ExpiryBaseOverride      *string             `json:"expiry_base_override" description:"分配生效条件覆盖，null 表示跟随套餐默认值"`
	ExpiryBaseOverrideName  string              `json:"expiry_base_override_name" description:"分配生效条件覆盖名称（中文）"`
	EffectiveExpiryBase     string              `json:"effective_expiry_base" description:"最终生效条件 (from_activation:实名激活时生效, from_purchase:购买即生效)"`
	EffectiveExpiryBaseName string              `json:"effective_expiry_base_name" description:"最终生效条件名称（中文）"`
}

// UpdatePackageParams 更新套餐聚合参数
type UpdatePackageParams struct {
	IDReq
	UpdatePackageRequest
}

// UpdatePackageStatusParams 更新套餐状态聚合参数
type UpdatePackageStatusParams struct {
	IDReq
	UpdatePackageStatusRequest
}

// UpdatePackageShelfStatusParams 更新套餐上架状态聚合参数
type UpdatePackageShelfStatusParams struct {
	IDReq
	UpdatePackageShelfStatusRequest
}

// UpdateRetailPriceParams 更新零售价聚合参数
type UpdateRetailPriceParams struct {
	IDReq
	UpdateRetailPriceRequest
}

// PackagePageResult 套餐分页结果
type PackagePageResult struct {
	List     []*PackageResponse `json:"items" description:"套餐列表"`
	Total    int64              `json:"total" description:"总数"`
	Page     int                `json:"page" description:"当前页"`
	PageSize int                `json:"size" description:"每页数量"`
}

// PackageUsageItemResponse 套餐使用项响应（客户视图）
type PackageUsageItemResponse struct {
	PackageUsageID uint   `json:"package_usage_id" description:"套餐使用记录ID"`
	PackageID      uint   `json:"package_id" description:"套餐ID"`
	PackageName    string `json:"package_name" description:"套餐名称"`
	UsedMB         int64  `json:"used_mb" description:"已使用流量(MB)"`
	TotalMB        int64  `json:"total_mb" description:"总流量(MB)"`
	Status         int    `json:"status" description:"状态 (0:待生效, 1:生效中, 2:已用完, 3:已过期, 4:已失效)"`
	StatusText     string `json:"status_text" description:"状态文本"`
	ExpiresAt      string `json:"expires_at" description:"过期时间"`
	ActivatedAt    string `json:"activated_at" description:"激活时间"`
	Priority       int    `json:"priority" description:"优先级（数字越小优先级越高）"`
}

// PackageUsageTotalInfo 套餐流量总计信息
type PackageUsageTotalInfo struct {
	UsedMB  int64 `json:"used_mb" description:"总已使用流量(MB)"`
	TotalMB int64 `json:"total_mb" description:"总流量(MB)"`
}

// PackageUsageCustomerViewResponse 客户视图流量查询响应
type PackageUsageCustomerViewResponse struct {
	MainPackage   *PackageUsageItemResponse  `json:"main_package" description:"主套餐信息"`
	AddonPackages []PackageUsageItemResponse `json:"addon_packages" description:"加油包列表（按priority排序）"`
	Total         PackageUsageTotalInfo      `json:"total" description:"总计流量信息"`
}

// PackageUsageDailyRecordResponse 套餐流量日记录响应
type PackageUsageDailyRecordResponse struct {
	Date              string `json:"date" description:"日期"`
	DailyUsageMB      int    `json:"daily_usage_mb" description:"当日流量使用量(MB)"`
	CumulativeUsageMB int64  `json:"cumulative_usage_mb" description:"截止当日的累计流量(MB)"`
}

// PackageUsageDetailResponse 套餐流量详单响应
type PackageUsageDetailResponse struct {
	PackageUsageID uint                              `json:"package_usage_id" description:"套餐使用记录ID"`
	PackageName    string                            `json:"package_name" description:"套餐名称"`
	Records        []PackageUsageDailyRecordResponse `json:"records" description:"流量日记录列表"`
	TotalUsageMB   int64                             `json:"total_usage_mb" description:"总使用流量(MB)"`
}
