using HoneyBox.Admin.Business.Models;
using HoneyBox.Admin.Business.Extensions;
using System.Text.Json.Serialization;

namespace HoneyBox.Admin.Business.Models.Goods;

#region Request Models

/// <summary>
/// 商品列表查询请求
/// </summary>
public class GoodsListRequest : PagedRequest
{
    /// <summary>
    /// 商品标题（模糊搜索）
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 商品状态：0-下架 1-上架
    /// </summary>
    public int? Status { get; set; }

    /// <summary>
    /// 商品类型
    /// </summary>
    public int? Type { get; set; }
}

/// <summary>
/// 创建商品请求
/// </summary>
public class GoodsCreateRequest
{
    /// <summary>
    /// 商品标题
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 商品价格
    /// </summary>
    public decimal Price { get; set; }

    /// <summary>
    /// 商品类型：1-一番赏 2-无限赏 3-擂台赏 4-抽卡机 5-福袋 6-幸运赏 8-盲盒 9-扭蛋 15-福利屋
    /// </summary>
    public int Type { get; set; }

    /// <summary>
    /// 商品图片URL
    /// </summary>
    public string ImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 商品Banner图片URL（详情页顶部）
    /// </summary>
    public string? ImgUrlBanner { get; set; }

    /// <summary>
    /// 商品详情图片URL
    /// </summary>
    public string ImgUrlDetail { get; set; } = string.Empty;

    /// <summary>
    /// 库存数量
    /// </summary>
    public int Stock { get; set; }

    /// <summary>
    /// 排序值
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    /// 每日限购数量
    /// </summary>
    public int DailyLimit { get; set; }

    /// <summary>
    /// 是否锁定 0-否 1-是
    /// </summary>
    public int LockIs { get; set; }

    /// <summary>
    /// 锁定时间（分钟）
    /// </summary>
    public int LockTime { get; set; }

    /// <summary>
    /// 是否支持积分 0-否 1-是
    /// </summary>
    public int IntegralIs { get; set; }

    /// <summary>
    /// 是否显示 0-否 1-是
    /// </summary>
    public int ShowIs { get; set; }

    /// <summary>
    /// 是否支持优惠券 0-否 1-是
    /// </summary>
    public int CouponIs { get; set; }

    /// <summary>
    /// 优惠券比例
    /// </summary>
    public int CouponPro { get; set; }

    /// <summary>
    /// 福利屋开始时间
    /// </summary>
    [JsonConverter(typeof(FlexibleDateTimeConverter))]
    public DateTime? FlwStartTime { get; set; }

    /// <summary>
    /// 福利屋结束时间
    /// </summary>
    [JsonConverter(typeof(FlexibleDateTimeConverter))]
    public DateTime? FlwEndTime { get; set; }

    /// <summary>
    /// 开放时间
    /// </summary>
    [JsonConverter(typeof(FlexibleDateTimeConverter))]
    public DateTime? OpenTime { get; set; }

    /// <summary>
    /// 抽奖限制次数
    /// </summary>
    public int? ChoujiangXianzhi { get; set; }

    /// <summary>
    /// 分类ID
    /// </summary>
    public int CategoryId { get; set; }

    /// <summary>
    /// 商品描述
    /// </summary>
    public string? GoodsDescribe { get; set; }

    /// <summary>
    /// 是否新品 0-否 1-是
    /// </summary>
    public int NewIs { get; set; }

    /// <summary>
    /// 是否首折 0-否 1-是
    /// </summary>
    public int IsShouZhe { get; set; }

    /// <summary>
    /// 是否开启暴怒 0-否 1-是
    /// </summary>
    public int RageIs { get; set; }

    /// <summary>
    /// 暴怒值
    /// </summary>
    public int Rage { get; set; }

    /// <summary>
    /// 是否开启灵珠 0-否 1-是
    /// </summary>
    public int LingzhuIs { get; set; }

    /// <summary>
    /// 灵珠翻倍
    /// </summary>
    public int LingzhuFan { get; set; }

    /// <summary>
    /// 是否自动下架 0-否 1-是
    /// </summary>
    public int IsAutoXiajia { get; set; }

    /// <summary>
    /// 下架利润值(%)
    /// </summary>
    public decimal XiajiaLirun { get; set; }

    /// <summary>
    /// 下架抽数阈值
    /// </summary>
    public int XiajiaAutoCoushu { get; set; }

    /// <summary>
    /// 下架金额
    /// </summary>
    public decimal XiajiaJine { get; set; }

    /// <summary>
    /// 解锁金额（用户需消费满此金额才能看到此盒子，0表示无需解锁）
    /// </summary>
    public decimal UnlockAmount { get; set; }
}

/// <summary>
/// 更新商品请求
/// </summary>
public class GoodsUpdateRequest : GoodsCreateRequest
{
}

/// <summary>
/// 商品状态更新请求
/// </summary>
public class GoodsStatusRequest
{
    /// <summary>
    /// 状态：0-下架 1-上架
    /// </summary>
    public int Status { get; set; }
}

#endregion

#region Response Models

/// <summary>
/// 商品列表响应
/// </summary>
public class GoodsListResponse
{
    /// <summary>
    /// 商品ID
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// 商品标题
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 商品图片URL
    /// </summary>
    public string ImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 商品Banner图片URL（详情页顶部）
    /// </summary>
    public string? ImgUrlBanner { get; set; }

    /// <summary>
    /// 商品价格
    /// </summary>
    public decimal Price { get; set; }

    /// <summary>
    /// 商品类型
    /// </summary>
    public int Type { get; set; }

    /// <summary>
    /// 商品类型名称
    /// </summary>
    public string TypeName { get; set; } = string.Empty;

    /// <summary>
    /// 状态：0-下架 1-上架
    /// </summary>
    public int Status { get; set; }

    /// <summary>
    /// 总库存
    /// </summary>
    public int Stock { get; set; }

    /// <summary>
    /// 已售库存
    /// </summary>
    public int SaleStock { get; set; }

    /// <summary>
    /// 剩余库存
    /// </summary>
    public int RemainingStock => Stock - SaleStock;

    /// <summary>
    /// 排序值
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    /// 福利屋开始时间
    /// </summary>
    public DateTime? FlwStartTime { get; set; }

    /// <summary>
    /// 福利屋结束时间
    /// </summary>
    public DateTime? FlwEndTime { get; set; }

    /// <summary>
    /// 开奖时间
    /// </summary>
    public DateTime? OpenTime { get; set; }

    /// <summary>
    /// 抽奖门槛
    /// </summary>
    public int ChoujiangXianzhi { get; set; }

    /// <summary>
    /// 解锁金额
    /// </summary>
    public decimal UnlockAmount { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime UpdatedAt { get; set; }
}

/// <summary>
/// 商品详情响应
/// </summary>
public class GoodsDetailResponse : GoodsListResponse
{
    /// <summary>
    /// 商品详情图片URL
    /// </summary>
    public string ImgUrlDetail { get; set; } = string.Empty;

    /// <summary>
    /// 分类ID
    /// </summary>
    public int CategoryId { get; set; }

    /// <summary>
    /// 每日限购数量
    /// </summary>
    public int DailyLimit { get; set; }

    /// <summary>
    /// 是否锁定 0-否 1-是
    /// </summary>
    public int LockIs { get; set; }

    /// <summary>
    /// 锁定时间（秒）
    /// </summary>
    public int? LockTime { get; set; }

    /// <summary>
    /// 是否支持积分 0-否 1-是
    /// </summary>
    public int IntegralIs { get; set; }

    /// <summary>
    /// 是否显示 0-否 1-是
    /// </summary>
    public int ShowIs { get; set; }

    /// <summary>
    /// 是否支持优惠券 0-否 1-是
    /// </summary>
    public int CouponIs { get; set; }

    /// <summary>
    /// 优惠券比例
    /// </summary>
    public int CouponPro { get; set; }

    /// <summary>
    /// 商品描述
    /// </summary>
    public string? GoodsDescribe { get; set; }

    /// <summary>
    /// 是否新品 0-否 1-是
    /// </summary>
    public int NewIs { get; set; }

    /// <summary>
    /// 是否首折 0-否 1-是
    /// </summary>
    public int IsShouZhe { get; set; }

    /// <summary>
    /// 是否开启暴怒 0-否 1-是
    /// </summary>
    public int RageIs { get; set; }

    /// <summary>
    /// 暴怒值
    /// </summary>
    public int Rage { get; set; }

    /// <summary>
    /// 是否开启灵珠 0-否 1-是
    /// </summary>
    public int LingzhuIs { get; set; }

    /// <summary>
    /// 灵珠翻倍
    /// </summary>
    public int LingzhuFan { get; set; }

    /// <summary>
    /// 奖品数量
    /// </summary>
    public int PrizeNum { get; set; }

    /// <summary>
    /// 是否福利屋商品 0-否 1-是
    /// </summary>
    public int IsFlw { get; set; }
}

/// <summary>
/// 盒子类型响应
/// </summary>
public class GoodsTypeDto
{
    /// <summary>
    /// 类型ID
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// 类型名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 类型值（Key）
    /// </summary>
    public int Value { get; set; }

    /// <summary>
    /// 排序值
    /// </summary>
    public int SortOrder { get; set; }

    /// <summary>
    /// 是否首页显示 0-否 1-是
    /// </summary>
    public int IsShow { get; set; }

    /// <summary>
    /// 是否分类显示 0-否 1-是
    /// </summary>
    public int IsFenlei { get; set; }

    /// <summary>
    /// 分类名称
    /// </summary>
    public string FlName { get; set; } = string.Empty;

    /// <summary>
    /// 角标文字
    /// </summary>
    public string? CornerText { get; set; }

    /// <summary>
    /// 是否支持微信支付 0-否 1-是
    /// </summary>
    public int PayWechat { get; set; }

    /// <summary>
    /// 是否支持余额支付 0-否 1-是
    /// </summary>
    public int PayBalance { get; set; }

    /// <summary>
    /// 是否支持货币1支付（HH币/吧唧币）0-否 1-是
    /// </summary>
    public int PayCurrency { get; set; }

    /// <summary>
    /// 是否支持货币2支付（哈尼券）0-否 1-是
    /// </summary>
    public int PayCurrency2 { get; set; }

    /// <summary>
    /// 是否支持优惠券 0-否 1-是
    /// </summary>
    public int PayCoupon { get; set; }

    /// <summary>
    /// 支付类型：0-抵扣模式 1-支付模式
    /// </summary>
    public int IsDeduction { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string? Remark { get; set; }
}

/// <summary>
/// 盒子类型列表响应（包含货币名称配置）
/// </summary>
public class GoodsTypesResponse
{
    /// <summary>
    /// 盒子类型列表
    /// </summary>
    public List<GoodsTypeDto> List { get; set; } = new();

    /// <summary>
    /// 货币名称配置
    /// </summary>
    public CurrencyNamesDto CurrencyNames { get; set; } = new();
}

/// <summary>
/// 货币名称配置
/// </summary>
public class CurrencyNamesDto
{
    /// <summary>
    /// 余额名称（如：钻石）
    /// </summary>
    public string BalanceName { get; set; } = "余额";

    /// <summary>
    /// 货币1名称（如：HH币、吧唧币）
    /// </summary>
    public string Currency1Name { get; set; } = "吧唧币";

    /// <summary>
    /// 货币2名称（如：哈尼券）
    /// </summary>
    public string Currency2Name { get; set; } = "哈尼券";
}

#endregion
