using System.Text.Json.Serialization;

namespace HoneyBox.Admin.Business.Models.Config;

/// <summary>
/// 配置更新请求
/// </summary>
public class ConfigUpdateRequest
{
    /// <summary>
    /// 配置值（JSON对象）
    /// </summary>
    public object? Value { get; set; }
}

/// <summary>
/// 配置响应
/// </summary>
public class ConfigResponse
{
    /// <summary>
    /// 配置键
    /// </summary>
    public string Key { get; set; } = string.Empty;

    /// <summary>
    /// 配置值
    /// </summary>
    public object? Value { get; set; }
}

/// <summary>
/// 微信支付配置
/// </summary>
public class WeixinPaySetting
{
    /// <summary>
    /// 商户列表
    /// </summary>
    [JsonPropertyName("merchants")]
    public List<WeixinPayMerchant> Merchants { get; set; } = new();
}

/// <summary>
/// 微信支付商户配置
/// </summary>
public class WeixinPayMerchant
{
    /// <summary>
    /// 商户名称
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 商户号
    /// </summary>
    [JsonPropertyName("mch_id")]
    public string MchId { get; set; } = string.Empty;

    /// <summary>
    /// 订单前缀（必须3位）
    /// </summary>
    [JsonPropertyName("order_prefix")]
    public string OrderPrefix { get; set; } = string.Empty;

    /// <summary>
    /// API密钥（V2版本使用）
    /// </summary>
    [JsonPropertyName("api_key")]
    public string? ApiKey { get; set; }

    /// <summary>
    /// 证书路径
    /// </summary>
    [JsonPropertyName("cert_path")]
    public string? CertPath { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    [JsonPropertyName("is_enabled")]
    public string? IsEnabled { get; set; }

    // ===== V3 新增字段 =====

    /// <summary>
    /// 支付版本: "V2" 或 "V3"，默认 "V2"
    /// </summary>
    [JsonPropertyName("pay_version")]
    public string PayVersion { get; set; } = "V2";

    /// <summary>
    /// APIv3 密钥（32位字符串，V3版本使用）
    /// </summary>
    [JsonPropertyName("api_v3_key")]
    public string? ApiV3Key { get; set; }

    /// <summary>
    /// 商户API证书序列号（V3版本使用）
    /// </summary>
    [JsonPropertyName("cert_serial_no")]
    public string? CertSerialNo { get; set; }

    /// <summary>
    /// 商户私钥文件路径（V3版本使用）
    /// </summary>
    [JsonPropertyName("private_key_path")]
    public string? PrivateKeyPath { get; set; }

    /// <summary>
    /// 微信支付公钥ID（V3版本使用）
    /// </summary>
    [JsonPropertyName("wechat_public_key_id")]
    public string? WechatPublicKeyId { get; set; }

    /// <summary>
    /// 微信支付公钥文件路径（V3版本使用）
    /// </summary>
    [JsonPropertyName("wechat_public_key_path")]
    public string? WechatPublicKeyPath { get; set; }
}


/// <summary>
/// 小程序配置
/// </summary>
public class MiniprogramSetting
{
    /// <summary>
    /// 小程序列表
    /// </summary>
    [JsonPropertyName("miniprograms")]
    public List<MiniprogramConfig> Miniprograms { get; set; } = new();
}

/// <summary>
/// 小程序配置项
/// </summary>
public class MiniprogramConfig
{
    /// <summary>
    /// 小程序名称
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// AppId
    /// </summary>
    [JsonPropertyName("appid")]
    public string AppId { get; set; } = string.Empty;

    /// <summary>
    /// AppSecret
    /// </summary>
    [JsonPropertyName("appsecret")]
    public string? AppSecret { get; set; }

    /// <summary>
    /// 订单前缀（必须2位）
    /// </summary>
    [JsonPropertyName("order_prefix")]
    public string? OrderPrefix { get; set; }

    /// <summary>
    /// 是否默认
    /// </summary>
    [JsonPropertyName("is_default")]
    public int IsDefault { get; set; }

    /// <summary>
    /// 关联商户列表
    /// </summary>
    [JsonPropertyName("merchants")]
    public List<string>? Merchants { get; set; }
}

/// <summary>
/// H5配置
/// </summary>
public class H5Setting
{
    /// <summary>
    /// H5应用列表
    /// </summary>
    [JsonPropertyName("h5apps")]
    public List<H5AppConfig> H5Apps { get; set; } = new();
}

/// <summary>
/// H5应用配置项
/// </summary>
public class H5AppConfig
{
    /// <summary>
    /// 应用名称
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 订单前缀（必须2位）
    /// </summary>
    [JsonPropertyName("order_prefix")]
    public string? OrderPrefix { get; set; }

    /// <summary>
    /// 是否默认
    /// </summary>
    [JsonPropertyName("is_default")]
    public int IsDefault { get; set; }

    /// <summary>
    /// 微信商户索引
    /// </summary>
    [JsonPropertyName("wx_merchant_index")]
    public int? WxMerchantIndex { get; set; }

    /// <summary>
    /// 支付宝商户索引
    /// </summary>
    [JsonPropertyName("ali_merchant_index")]
    public int? AliMerchantIndex { get; set; }
}

/// <summary>
/// 支持的配置键
/// </summary>
public static class ConfigKeys
{
    public const string Base = "base";
    public const string WeixinPaySetting = "weixinpay_setting";
    public const string AlipayPaySetting = "alipay_setting";
    public const string MiniprogramSetting = "miniprogram_setting";
    public const string H5Setting = "h5_setting";
    public const string Uploads = "uploads";
    public const string SystemConfig = "systemconfig";
    public const string Sign = "sign";
    public const string AppSetting = "app_setting";
    public const string UserConfig = "user_config";
    public const string InfiniteMultiple = "infinite_multiple";
    public const string RankSetting = "rank_setting";
    public const string SystemTest = "system_test";
    public const string TencentSmsConfig = "tencent_sms_config";

    /// <summary>
    /// 所有支持的配置键
    /// </summary>
    public static readonly string[] AllKeys = new[]
    {
        Base, WeixinPaySetting, AlipayPaySetting, MiniprogramSetting, H5Setting,
        Uploads, SystemConfig, Sign, AppSetting, UserConfig, InfiniteMultiple,
        RankSetting, SystemTest, TencentSmsConfig
    };

    /// <summary>
    /// 检查配置键是否有效
    /// </summary>
    public static bool IsValidKey(string key) => AllKeys.Contains(key);
}

#region 支付宝配置模型

/// <summary>
/// 支付宝配置
/// </summary>
public class AlipaySetting
{
    /// <summary>
    /// 商户列表
    /// </summary>
    [JsonPropertyName("merchants")]
    public List<AlipayMerchant> Merchants { get; set; } = new();
}

/// <summary>
/// 支付宝商户配置
/// </summary>
public class AlipayMerchant
{
    /// <summary>
    /// 商户名称
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 应用ID
    /// </summary>
    [JsonPropertyName("appId")]
    public string AppId { get; set; } = string.Empty;

    /// <summary>
    /// 应用私钥
    /// </summary>
    [JsonPropertyName("privateKey")]
    public string? PrivateKey { get; set; }

    /// <summary>
    /// 支付宝公钥
    /// </summary>
    [JsonPropertyName("publicKey")]
    public string? PublicKey { get; set; }

    /// <summary>
    /// 权重
    /// </summary>
    [JsonPropertyName("weight")]
    public int Weight { get; set; } = 1;

    /// <summary>
    /// 是否启用 0禁用 1启用
    /// </summary>
    [JsonPropertyName("is_enabled")]
    public int IsEnabled { get; set; } = 1;

    /// <summary>
    /// 备注
    /// </summary>
    [JsonPropertyName("remark")]
    public string? Remark { get; set; }
}

#endregion

#region 基础设置模型

/// <summary>
/// 基础设置
/// </summary>
public class BaseSetting
{
    /// <summary>
    /// 网站名称
    /// </summary>
    [JsonPropertyName("title")]
    public string? Title { get; set; }

    /// <summary>
    /// 物流code
    /// </summary>
    [JsonPropertyName("logistics_code")]
    public string? LogisticsCode { get; set; }

    /// <summary>
    /// 连击赏最大抽取次数
    /// </summary>
    [JsonPropertyName("lianji_max_num")]
    public string? LianjiMaxNum { get; set; }

    /// <summary>
    /// 分销奖励比例
    /// </summary>
    [JsonPropertyName("fx_bili")]
    public string? FxBili { get; set; }

    /// <summary>
    /// 赏券每人每天最多领取次数
    /// </summary>
    [JsonPropertyName("coupon_ling_max_ci")]
    public string? CouponLingMaxCi { get; set; }

    /// <summary>
    /// 特级赏券限制参与人数
    /// </summary>
    [JsonPropertyName("coupon_a_xz_max")]
    public string? CouponAXzMax { get; set; }

    /// <summary>
    /// 终极赏券限制参与人数
    /// </summary>
    [JsonPropertyName("coupon_b_xz_max")]
    public string? CouponBXzMax { get; set; }

    /// <summary>
    /// 高级赏券限制参与人数
    /// </summary>
    [JsonPropertyName("coupon_c_xz_max")]
    public string? CouponCXzMax { get; set; }

    /// <summary>
    /// 普通赏券限制参与人数
    /// </summary>
    [JsonPropertyName("coupon_d_xz_max")]
    public string? CouponDXzMax { get; set; }

    /// <summary>
    /// 背包满多少包邮
    /// </summary>
    [JsonPropertyName("free_post")]
    public string? FreePost { get; set; }

    /// <summary>
    /// 背包发货运费
    /// </summary>
    [JsonPropertyName("post_money")]
    public string? PostMoney { get; set; }

    /// <summary>
    /// 一番赏三发+时间(秒)
    /// </summary>
    [JsonPropertyName("three_time")]
    public string? ThreeTime { get; set; }

    /// <summary>
    /// 一番赏五发+时间(秒)
    /// </summary>
    [JsonPropertyName("five_time")]
    public string? FiveTime { get; set; }

    /// <summary>
    /// 福利进群二维码
    /// </summary>
    [JsonPropertyName("erweima")]
    public string? Erweima { get; set; }

    /// <summary>
    /// 分享标题
    /// </summary>
    [JsonPropertyName("share_title")]
    public string? ShareTitle { get; set; }

    /// <summary>
    /// 分享图片
    /// </summary>
    [JsonPropertyName("share_image")]
    public string? ShareImage { get; set; }

    /// <summary>
    /// 海报模板图片URL
    /// </summary>
    [JsonPropertyName("poster_template")]
    public string? PosterTemplate { get; set; }

    /// <summary>
    /// 海报二维码X坐标
    /// </summary>
    [JsonPropertyName("poster_qr_x")]
    public string? PosterQrX { get; set; }

    /// <summary>
    /// 海报二维码Y坐标
    /// </summary>
    [JsonPropertyName("poster_qr_y")]
    public string? PosterQrY { get; set; }

    /// <summary>
    /// 海报二维码大小
    /// </summary>
    [JsonPropertyName("poster_qr_size")]
    public string? PosterQrSize { get; set; }

    /// <summary>
    /// 站点URL
    /// </summary>
    [JsonPropertyName("site_url")]
    public string? SiteUrl { get; set; }

    /// <summary>
    /// 抽奖券拉人上限
    /// </summary>
    [JsonPropertyName("draw_people_num")]
    public string? DrawPeopleNum { get; set; }

    /// <summary>
    /// 首页是否弹窗 0关闭 1开启
    /// </summary>
    [JsonPropertyName("is_shou_tan")]
    public string? IsShouTan { get; set; }

    /// <summary>
    /// 兑换开关 0关闭 1开启
    /// </summary>
    [JsonPropertyName("is_exchange")]
    public string? IsExchange { get; set; }
}

#endregion

#region 签到配置模型

/// <summary>
/// 签到配置
/// </summary>
public class SignSetting
{
    /// <summary>
    /// 第一天奖励
    /// </summary>
    [JsonPropertyName("one_num")]
    public string? OneNum { get; set; }

    /// <summary>
    /// 第二天奖励
    /// </summary>
    [JsonPropertyName("two_num")]
    public string? TwoNum { get; set; }

    /// <summary>
    /// 第三天奖励
    /// </summary>
    [JsonPropertyName("three_num")]
    public string? ThreeNum { get; set; }

    /// <summary>
    /// 第四天奖励
    /// </summary>
    [JsonPropertyName("four_num")]
    public string? FourNum { get; set; }

    /// <summary>
    /// 第五天奖励
    /// </summary>
    [JsonPropertyName("five_num")]
    public string? FiveNum { get; set; }

    /// <summary>
    /// 第六天奖励
    /// </summary>
    [JsonPropertyName("six_num")]
    public string? SixNum { get; set; }

    /// <summary>
    /// 第七天奖励
    /// </summary>
    [JsonPropertyName("seven_num")]
    public string? SevenNum { get; set; }
}

#endregion

#region 应用设置模型

/// <summary>
/// 应用设置
/// </summary>
public class AppSetting
{
    /// <summary>
    /// 项目名称
    /// </summary>
    [JsonPropertyName("app_name")]
    public string? AppName { get; set; }

    /// <summary>
    /// 购买弹窗 1弹出一次 2每天显示
    /// </summary>
    [JsonPropertyName("purchase_popup")]
    public string? PurchasePopup { get; set; }

    /// <summary>
    /// 商城购买次数
    /// </summary>
    [JsonPropertyName("exchange_times")]
    public string? ExchangeTimes { get; set; }

    /// <summary>
    /// 余额名称
    /// </summary>
    [JsonPropertyName("balance_name")]
    public string? BalanceName { get; set; }

    /// <summary>
    /// 余额图标
    /// </summary>
    [JsonPropertyName("balance_icon")]
    public string? BalanceIcon { get; set; }

    /// <summary>
    /// 货币1名称
    /// </summary>
    [JsonPropertyName("currency1_name")]
    public string? Currency1Name { get; set; }

    /// <summary>
    /// 货币1图标
    /// </summary>
    [JsonPropertyName("currency1_icon")]
    public string? Currency1Icon { get; set; }

    /// <summary>
    /// 货币2名称
    /// </summary>
    [JsonPropertyName("currency2_name")]
    public string? Currency2Name { get; set; }

    /// <summary>
    /// 货币2图标
    /// </summary>
    [JsonPropertyName("currency2_icon")]
    public string? Currency2Icon { get; set; }

    /// <summary>
    /// 中奖音频
    /// </summary>
    [JsonPropertyName("win_audio")]
    public string? WinAudio { get; set; }

    /// <summary>
    /// 小程序版本号
    /// </summary>
    [JsonPropertyName("version")]
    public string? Version { get; set; }

    /// <summary>
    /// 签到消费门槛
    /// </summary>
    [JsonPropertyName("sign_threshold")]
    public string? SignThreshold { get; set; }

    /// <summary>
    /// 显示兑换达达券按钮门槛
    /// </summary>
    [JsonPropertyName("exchange_show_threshold")]
    public string? ExchangeShowThreshold { get; set; }

    /// <summary>
    /// 外卖盒子ID
    /// </summary>
    [JsonPropertyName("takeout_box_id")]
    public string? TakeoutBoxId { get; set; }

    /// <summary>
    /// 每日免费抽奖ID
    /// </summary>
    [JsonPropertyName("daily_free_draw_id")]
    public string? DailyFreeDrawId { get; set; }

    /// <summary>
    /// 盒柜兑换次数限制
    /// </summary>
    [JsonPropertyName("box_exchange_limit")]
    public string? BoxExchangeLimit { get; set; }

    /// <summary>
    /// 每天优惠券次数
    /// </summary>
    [JsonPropertyName("daily_coupon_limit")]
    public string? DailyCouponLimit { get; set; }
}

#endregion

#region 用户UID配置模型

/// <summary>
/// 用户UID配置
/// </summary>
public class UserConfigSetting
{
    /// <summary>
    /// UID类型 1真实ID 2数字ID 3随机字符和数字
    /// </summary>
    [JsonPropertyName("uid_type")]
    public string? UidType { get; set; }

    /// <summary>
    /// UID长度
    /// </summary>
    [JsonPropertyName("uid_length")]
    public string? UidLength { get; set; }
}

#endregion

#region 内测配置模型

/// <summary>
/// 内测配置
/// </summary>
public class SystemTestSetting
{
    /// <summary>
    /// 是否开启内测 0关闭 1开启
    /// </summary>
    [JsonPropertyName("enable_test")]
    public string? EnableTest { get; set; }

    /// <summary>
    /// 是否禁用微信支付 0启用 1禁用
    /// </summary>
    [JsonPropertyName("disable_wechat_pay")]
    public string? DisableWechatPay { get; set; }

    /// <summary>
    /// 签到倍数
    /// </summary>
    [JsonPropertyName("sign_multiple")]
    public string? SignMultiple { get; set; }
}

#endregion

#region 无限赏抽奖倍数模型

/// <summary>
/// 无限赏抽奖倍数配置
/// </summary>
public class InfiniteMultipleSetting
{
    /// <summary>
    /// 抽奖倍数 1000/10000/100000
    /// </summary>
    [JsonPropertyName("multiple")]
    public string? Multiple { get; set; }
}

#endregion

#region 排行榜设置模型

/// <summary>
/// 排行榜设置
/// </summary>
public class RankSettingSetting
{
    /// <summary>
    /// 达达券排行榜统计方式 daily/weekly/monthly/yearly/custom
    /// </summary>
    [JsonPropertyName("dadajuan_stat_type")]
    public string? DadajuanStatType { get; set; }

    /// <summary>
    /// 达达券自定义开始时间
    /// </summary>
    [JsonPropertyName("dadajuan_start_time")]
    public string? DadajuanStartTime { get; set; }

    /// <summary>
    /// 达达券自定义结束时间
    /// </summary>
    [JsonPropertyName("dadajuan_end_time")]
    public string? DadajuanEndTime { get; set; }

    /// <summary>
    /// 钻石排行榜统计方式
    /// </summary>
    [JsonPropertyName("diamond_stat_type")]
    public string? DiamondStatType { get; set; }

    /// <summary>
    /// 钻石自定义开始时间
    /// </summary>
    [JsonPropertyName("diamond_start_time")]
    public string? DiamondStartTime { get; set; }

    /// <summary>
    /// 钻石自定义结束时间
    /// </summary>
    [JsonPropertyName("diamond_end_time")]
    public string? DiamondEndTime { get; set; }

    /// <summary>
    /// UU币排行榜统计方式
    /// </summary>
    [JsonPropertyName("integral_stat_type")]
    public string? IntegralStatType { get; set; }

    /// <summary>
    /// UU币自定义开始时间
    /// </summary>
    [JsonPropertyName("integral_start_time")]
    public string? IntegralStartTime { get; set; }

    /// <summary>
    /// UU币自定义结束时间
    /// </summary>
    [JsonPropertyName("integral_end_time")]
    public string? IntegralEndTime { get; set; }

    /// <summary>
    /// 邀请排行榜统计方式
    /// </summary>
    [JsonPropertyName("invite_stat_type")]
    public string? InviteStatType { get; set; }

    /// <summary>
    /// 邀请自定义开始时间
    /// </summary>
    [JsonPropertyName("invite_start_time")]
    public string? InviteStartTime { get; set; }

    /// <summary>
    /// 邀请自定义结束时间
    /// </summary>
    [JsonPropertyName("invite_end_time")]
    public string? InviteEndTime { get; set; }
}

#endregion

#region 上传配置模型

/// <summary>
/// 上传配置
/// </summary>
public class UploadSetting
{
    /// <summary>
    /// 存储类型 1本地 2阿里云 3腾讯云
    /// </summary>
    [JsonPropertyName("type")]
    public string? Type { get; set; }

    /// <summary>
    /// 腾讯云AppId
    /// </summary>
    [JsonPropertyName("AppId")]
    public string? AppId { get; set; }

    /// <summary>
    /// 空间名称/Bucket
    /// </summary>
    [JsonPropertyName("Bucket")]
    public string? Bucket { get; set; }

    /// <summary>
    /// 地域
    /// </summary>
    [JsonPropertyName("Region")]
    public string? Region { get; set; }

    /// <summary>
    /// AccessKeyId
    /// </summary>
    [JsonPropertyName("AccessKeyId")]
    public string? AccessKeyId { get; set; }

    /// <summary>
    /// AccessKeySecret
    /// </summary>
    [JsonPropertyName("AccessKeySecret")]
    public string? AccessKeySecret { get; set; }

    /// <summary>
    /// 请求域名
    /// </summary>
    [JsonPropertyName("Domain")]
    public string? Domain { get; set; }
}


#endregion
