package commerce

// BusinessSettingSpec mirrors the legacy Python SETTING_SPECS metadata so the
// admin settings UI can group and validate business rule fields. The system_settings
// table itself only stores key/value/label/description; group/value_type/min/max/unit
// are static metadata, not persisted columns.
type BusinessSettingSpec struct {
	Label       string
	Description string
	ValueType   string
	MinValue    *int
	MaxValue    *int
	Unit        string
	Group       string
}

func intPtr(v int) *int { return &v }

var businessSettingSpecs = map[string]BusinessSettingSpec{
	"refund.full_refund_days": {
		Label: "全额退订天数", Description: "订单开通后多少天内可全额退订。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(30), Unit: "天", Group: "refund",
	},
	"refund.full_refund_limit": {
		Label: "全额退订次数", Description: "每个用户最多可使用的全额退订次数。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(3), Unit: "次", Group: "refund",
	},
	"lifecycle.expire_suspend_after_days": {
		Label: "到期暂停天数", Description: "实例到期后多少天自动暂停，0 表示到期立即暂停。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(30), Unit: "天", Group: "lifecycle",
	},
	"lifecycle.expire_delete_after_days": {
		Label: "到期删除天数", Description: "实例到期后多少天自动强制删除。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(365), Unit: "天", Group: "lifecycle",
	},
	"upstream.task_sync_interval_seconds": {
		Label: "任务同步频率", Description: "上游资源操作任务状态同步间隔，单位秒。",
		ValueType: "integer", MinValue: intPtr(30), MaxValue: intPtr(3600), Unit: "秒", Group: "upstream",
	},
	"upstream.stock_sync_interval_minutes": {
		Label: "魔方库存同步频率", Description: "已绑定魔方财务产品的上游库存同步间隔，单位分钟。",
		ValueType: "integer", MinValue: intPtr(5), MaxValue: intPtr(1440), Unit: "分钟", Group: "upstream",
	},
	"platform.site_name": {
		Label: "站点名称", Description: "用于后台展示、支付订单名称和部分通知文案。",
		ValueType: "text", MinValue: intPtr(2), MaxValue: intPtr(40), Group: "platform",
	},
	"platform.registration_enabled": {
		Label: "开放新用户注册", Description: "关闭后新用户无法获取注册验证码或完成注册，已有用户登录不受影响。",
		ValueType: "boolean", Group: "platform",
	},
	"platform.frontend_url": {
		Label: "前台访问地址", Description: "用于邮件通知、跳转链接等场景。",
		ValueType: "url", MinValue: intPtr(8), MaxValue: intPtr(200), Group: "platform",
	},
	"platform.backend_url": {
		Label: "后端公开访问地址", Description: "用于魔方财务等上游系统回调本站后端，例如 https://api.example.com。",
		ValueType: "url", MinValue: intPtr(0), MaxValue: intPtr(200), Group: "platform",
	},
	"platform.promotion_base_url": {
		Label: "推广链接基础地址", Description: "推广码生成注册链接时使用的前台地址。",
		ValueType: "url", MinValue: intPtr(8), MaxValue: intPtr(200), Group: "platform",
	},
	"finance.recharge_min_cents": {
		Label: "最低充值金额", Description: "用户单笔充值的最低金额。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(1_000_000), Unit: "分", Group: "finance",
	},
	"finance.recharge_max_cents": {
		Label: "最高充值金额", Description: "用户单笔充值的最高金额。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(100_000_000), Unit: "分", Group: "finance",
	},
	"finance.pending_payment_ttl_minutes": {
		Label: "待支付保留时间", Description: "充值订单创建后，前台保留待支付入口的时间。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(120), Unit: "分钟", Group: "finance",
	},
	"finance.recharge_enabled": {
		Label: "开放余额充值", Description: "关闭后用户不能创建新的充值订单，已创建订单和支付回调仍会继续处理。",
		ValueType: "boolean", Group: "finance",
	},
	"promotion.invite_code_edit_enabled": {
		Label: "允许自定义推广码", Description: "关闭后用户不能修改自己的推广码，已有推广码和绑定关系继续有效。",
		ValueType: "boolean", Group: "promotion",
	},
	"promotion.settlement_check_interval_minutes": {
		Label: "奖励释放扫描频率", Description: "后台扫描冻结代理收益和普通推广奖励的频率。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(120), Unit: "分钟", Group: "promotion",
	},
	"promotion.min_agent_balance_for_subsidy_coupon_cents": {
		Label: "代理补贴券最低余额门槛", Description: "代理创建可能低于成本的折扣券时，要求的最低代理余额。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(1_000_000), Unit: "分", Group: "promotion",
	},
	"verification.free_quota_per_user": {
		Label: "每人免费实名次数", Description: "每个用户可免费发起实名认证的次数；按提交次数消耗，已实名用户不能继续提交。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(100), Unit: "次", Group: "verification",
	},
	"verification.quota_purchase_enabled": {
		Label: "允许购买实名次数", Description: "免费次数用完后，允许用户用余额购买实名认证提交次数。",
		ValueType: "boolean", Group: "verification",
	},
	"verification.quota_price_cents": {
		Label: "实名次数单价", Description: "用户购买一次实名认证提交次数的价格，单位分；350 表示 ¥3.50。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(100000), Unit: "分", Group: "verification",
	},
	"points.qq_answer": {
		Label: "QQ群任务正确答案", Description: "用户完成加入QQ群任务时需填写的群主QQ号。",
		ValueType: "text", MinValue: intPtr(1), MaxValue: intPtr(64), Group: "points",
	},
	"points.bilibili_answer": {
		Label: "B站关注任务正确答案", Description: "用户完成关注B站任务时需填写的B站用户名。",
		ValueType: "text", MinValue: intPtr(1), MaxValue: intPtr(64), Group: "points",
	},
	"points.qq_reward": {
		Label: "QQ群任务奖励积分", Description: "完成加入QQ群任务获得的积分。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(1_000_000), Unit: "积分", Group: "points",
	},
	"points.bilibili_reward": {
		Label: "B站关注任务奖励积分", Description: "完成关注B站任务获得的积分。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(1_000_000), Unit: "积分", Group: "points",
	},
	"points.checkin_min_points": {
		Label: "每日签到最低积分", Description: "每日签到随机奖励的最小积分值。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(1_000_000), Unit: "积分", Group: "points",
	},
	"points.checkin_max_points": {
		Label: "每日签到最高积分", Description: "每日签到随机奖励的最大积分值。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(1_000_000), Unit: "积分", Group: "points",
	},
	"points.withdraw_fee_rate": {
		Label: "积分提现手续费率", Description: "积分提现到余额的手续费率，单位为万分比，200 表示 2%。",
		ValueType: "integer", MinValue: intPtr(0), MaxValue: intPtr(10000), Unit: "‱", Group: "points",
	},
	"points.withdraw_min_points": {
		Label: "积分最低提现积分", Description: "积分提现的最低门槛，按积分计算。",
		ValueType: "integer", MinValue: intPtr(1), MaxValue: intPtr(1_000_000_000), Unit: "积分", Group: "points",
	},
}
