using System.Text.Json.Serialization;
using HoneyBox.Model.Models;
using HoneyBox.Model.Models.Goods;

namespace HoneyBox.Model.Models.Order;

#region Warehouse Request Models

/// <summary>
/// 仓库首页请求
/// </summary>
public class WarehouseIndexRequest : PageRequest
{
    /// <summary>
    /// 类型筛选：1=赏品，2=预售，3=卡册，4=保险柜，5=无限赏
    /// </summary>
    [JsonPropertyName("type")]
    public int Type { get; set; } = 1;

    /// <summary>
    /// 关键词搜索
    /// </summary>
    [JsonPropertyName("keyword")]
    public string? Keyword { get; set; }

    /// <summary>
    /// 分类ID（仅卡册类型使用）
    /// </summary>
    [JsonPropertyName("category_id")]
    public int CategoryId { get; set; } = 0;
}

/// <summary>
/// 奖品回收请求
/// </summary>
public class RecoveryRequest
{
    /// <summary>
    /// 回收信息JSON字符串，格式：[{"prize_code":"xxx","number":1}]
    /// </summary>
    [JsonPropertyName("recovery_info")]
    public string RecoveryInfo { get; set; } = string.Empty;
}

/// <summary>
/// 回收信息项
/// </summary>
public class RecoveryInfoItem
{
    /// <summary>
    /// 奖品编码
    /// </summary>
    [JsonPropertyName("prize_code")]
    public string PrizeCode { get; set; } = string.Empty;

    /// <summary>
    /// 回收数量
    /// </summary>
    [JsonPropertyName("number")]
    public int Number { get; set; }
}

/// <summary>
/// 奖品发货请求
/// </summary>
public class SendRequest
{
    /// <summary>
    /// 类型：1=背包，2=抽卡机
    /// </summary>
    [JsonPropertyName("type")]
    public int Type { get; set; } = 1;

    /// <summary>
    /// 发货信息JSON字符串，格式：[{"prize_code":"xxx","number":1}]
    /// </summary>
    [JsonPropertyName("recovery_info")]
    public string RecoveryInfo { get; set; } = string.Empty;

    /// <summary>
    /// 收货人姓名
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 收货人手机号
    /// </summary>
    [JsonPropertyName("mobile")]
    public string Mobile { get; set; } = string.Empty;

    /// <summary>
    /// 收货地址
    /// </summary>
    [JsonPropertyName("address")]
    public string Address { get; set; } = string.Empty;

    /// <summary>
    /// 留言备注
    /// </summary>
    [JsonPropertyName("message")]
    public string? Message { get; set; }
}

/// <summary>
/// 确认发货请求
/// </summary>
public class ConfirmSendRequest
{
    /// <summary>
    /// 发货记录ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }
}

/// <summary>
/// 发货记录请求
/// </summary>
public class SendRecordRequest : PageRequest
{
    /// <summary>
    /// 状态筛选：1=待发货，2=待收货，3=已完成
    /// </summary>
    [JsonPropertyName("status")]
    public int Status { get; set; } = 1;
}

/// <summary>
/// 发货记录详情请求
/// </summary>
public class SendRecordDetailRequest
{
    /// <summary>
    /// 发货记录ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }
}

/// <summary>
/// 回收记录请求
/// </summary>
public class RecoveryRecordRequest : PageRequest
{
}

/// <summary>
/// 物流信息请求
/// </summary>
public class LogisticsRequest
{
    /// <summary>
    /// 发货记录ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }
}

/// <summary>
/// 保险柜操作请求（移入/移出）
/// </summary>
public class SafeOperationRequest
{
    /// <summary>
    /// 操作信息JSON字符串，格式：[{"prize_code":"xxx","number":1}]
    /// </summary>
    [JsonPropertyName("recovery_info")]
    public string RecoveryInfo { get; set; } = string.Empty;
}

#endregion

#region Warehouse Response/DTO Models

/// <summary>
/// 仓库物品DTO
/// </summary>
public class WarehouseItemDto
{
    /// <summary>
    /// 订单详情ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 奖品标题
    /// </summary>
    [JsonPropertyName("goodslist_title")]
    public string GoodsListTitle { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片
    /// </summary>
    [JsonPropertyName("goodslist_imgurl")]
    public string GoodsListImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 奖品价格
    /// </summary>
    [JsonPropertyName("goodslist_price")]
    public string GoodsListPrice { get; set; } = "0.00";

    /// <summary>
    /// 回收金额
    /// </summary>
    [JsonPropertyName("goodslist_money")]
    public string GoodsListMoney { get; set; } = "0.00";

    /// <summary>
    /// 状态：0=待选择，1=已回收，2=已发货，3=集市
    /// </summary>
    [JsonPropertyName("status")]
    public int Status { get; set; }

    /// <summary>
    /// 创建时间戳
    /// </summary>
    [JsonPropertyName("addtime")]
    public long AddTime { get; set; }

    /// <summary>
    /// 赏品等级ID
    /// </summary>
    [JsonPropertyName("shang_id")]
    public int ShangId { get; set; }

    /// <summary>
    /// 赏品等级信息
    /// </summary>
    [JsonPropertyName("shang_info")]
    public ShangInfoDto? ShangInfo { get; set; }

    /// <summary>
    /// 商品ID
    /// </summary>
    [JsonPropertyName("goods_id")]
    public int GoodsId { get; set; }

    /// <summary>
    /// 商品标题
    /// </summary>
    [JsonPropertyName("goods_title")]
    public string? GoodsTitle { get; set; }

    /// <summary>
    /// 奖品类型：1=实物，2=虚拟
    /// </summary>
    [JsonPropertyName("goodslist_type")]
    public int GoodsListType { get; set; }

    /// <summary>
    /// 奖品编码
    /// </summary>
    [JsonPropertyName("prize_code")]
    public string? PrizeCode { get; set; }

    /// <summary>
    /// 奖品数量（同一prize_code的数量）
    /// </summary>
    [JsonPropertyName("prize_num")]
    public int PrizeNum { get; set; }

    /// <summary>
    /// 订单详情ID列表
    /// </summary>
    [JsonPropertyName("order_list_ids")]
    public List<int>? OrderListIds { get; set; }

    /// <summary>
    /// 赏品等级标题
    /// </summary>
    [JsonPropertyName("shang_title")]
    public string? ShangTitle { get; set; }

    /// <summary>
    /// 预售时间（仅预售类型）
    /// </summary>
    [JsonPropertyName("goodslist_sale_time")]
    public string? GoodsListSaleTime { get; set; }
}

/// <summary>
/// 仓库商品分组DTO
/// </summary>
public class WarehouseGoodsGroupDto
{
    /// <summary>
    /// 商品ID
    /// </summary>
    [JsonPropertyName("goods_id")]
    public int GoodsId { get; set; }

    /// <summary>
    /// 商品标题
    /// </summary>
    [JsonPropertyName("goods_title")]
    public string GoodsTitle { get; set; } = string.Empty;

    /// <summary>
    /// 奖品列表
    /// </summary>
    [JsonPropertyName("orderlist")]
    public List<WarehouseItemDto> OrderList { get; set; } = new();

    /// <summary>
    /// 奖品总数
    /// </summary>
    [JsonPropertyName("orderlist_total")]
    public int OrderListTotal { get; set; }

    /// <summary>
    /// 奖品种类数
    /// </summary>
    [JsonPropertyName("orderlist_length")]
    public int OrderListLength { get; set; }
}

/// <summary>
/// 仓库首页响应DTO
/// </summary>
public class WarehouseIndexResponseDto
{
    /// <summary>
    /// 总数量
    /// </summary>
    [JsonPropertyName("total")]
    public int Total { get; set; }

    /// <summary>
    /// 商品分组数据
    /// </summary>
    [JsonPropertyName("data")]
    public List<WarehouseGoodsGroupDto> Data { get; set; } = new();

    /// <summary>
    /// 最后一页
    /// </summary>
    [JsonPropertyName("last_page")]
    public int LastPage { get; set; } = 1;

    /// <summary>
    /// 运费设置
    /// </summary>
    [JsonPropertyName("yufei")]
    public ShippingFeeDto? Yufei { get; set; }

    /// <summary>
    /// 是否显示达达卷
    /// </summary>
    [JsonPropertyName("show_dadajuan")]
    public bool ShowDadajuan { get; set; } = true;
}

/// <summary>
/// 运费设置DTO
/// </summary>
public class ShippingFeeDto
{
    /// <summary>
    /// 免运费数量
    /// </summary>
    [JsonPropertyName("free_post")]
    public int FreePost { get; set; }

    /// <summary>
    /// 运费金额
    /// </summary>
    [JsonPropertyName("post_money")]
    public int PostMoney { get; set; }
}

/// <summary>
/// 卡册商品DTO
/// </summary>
public class CardAlbumDto
{
    /// <summary>
    /// 订单ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 商品ID
    /// </summary>
    [JsonPropertyName("goods_id")]
    public int GoodsId { get; set; }

    /// <summary>
    /// 商品标题
    /// </summary>
    [JsonPropertyName("goods_title")]
    public string GoodsTitle { get; set; } = string.Empty;

    /// <summary>
    /// 商品图片
    /// </summary>
    [JsonPropertyName("goods_imgurl")]
    public string GoodsImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 分类ID
    /// </summary>
    [JsonPropertyName("category_id")]
    public int CategoryId { get; set; }

    /// <summary>
    /// 全部奖品数量
    /// </summary>
    [JsonPropertyName("all_count")]
    public int AllCount { get; set; }

    /// <summary>
    /// 已获得数量
    /// </summary>
    [JsonPropertyName("buy_count")]
    public int BuyCount { get; set; }

    /// <summary>
    /// 收集进度百分比
    /// </summary>
    [JsonPropertyName("gailv")]
    public decimal Gailv { get; set; }
}

/// <summary>
/// 奖品回收结果DTO
/// </summary>
public class RecoveryResultDto
{
    /// <summary>
    /// 回收总金额
    /// </summary>
    [JsonPropertyName("total_money")]
    public string TotalMoney { get; set; } = "0.00";

    /// <summary>
    /// 回收数量
    /// </summary>
    [JsonPropertyName("count")]
    public int Count { get; set; }

    /// <summary>
    /// 回收单号
    /// </summary>
    [JsonPropertyName("recovery_num")]
    public string RecoveryNum { get; set; } = string.Empty;

    /// <summary>
    /// 用户当前余额
    /// </summary>
    [JsonPropertyName("user_money")]
    public string UserMoney { get; set; } = "0.00";
}

/// <summary>
/// 奖品发货结果DTO
/// </summary>
public class SendResultDto
{
    /// <summary>
    /// 状态：0=免运费直接发货，1=需要支付运费
    /// </summary>
    [JsonPropertyName("status")]
    public int Status { get; set; }

    /// <summary>
    /// 发货单号
    /// </summary>
    [JsonPropertyName("order_no")]
    public string OrderNo { get; set; } = string.Empty;

    /// <summary>
    /// 支付参数（需要支付运费时返回，原生微信支付参数）
    /// </summary>
    [JsonPropertyName("res")]
    public NativePayResultDto? Res { get; set; }
}

/// <summary>
/// 原生微信支付结果DTO（用于 uni.requestPayment）
/// </summary>
public class NativePayResultDto
{
    /// <summary>
    /// 小程序AppId
    /// </summary>
    [JsonPropertyName("appId")]
    public string AppId { get; set; } = string.Empty;

    /// <summary>
    /// 时间戳（秒）
    /// </summary>
    [JsonPropertyName("timeStamp")]
    public string TimeStamp { get; set; } = string.Empty;

    /// <summary>
    /// 随机字符串
    /// </summary>
    [JsonPropertyName("nonceStr")]
    public string NonceStr { get; set; } = string.Empty;

    /// <summary>
    /// 统一下单接口返回的 prepay_id（格式：prepay_id=xxx）
    /// </summary>
    [JsonPropertyName("package")]
    public string Package { get; set; } = string.Empty;

    /// <summary>
    /// 签名类型
    /// </summary>
    [JsonPropertyName("signType")]
    public string SignType { get; set; } = "MD5";

    /// <summary>
    /// 签名
    /// </summary>
    [JsonPropertyName("paySign")]
    public string PaySign { get; set; } = string.Empty;
}

/// <summary>
/// Web支付结果DTO（兼容前端支付流程，备用）
/// </summary>
public class WebPayResultDto
{
    /// <summary>
    /// 支付数据（包含订单号）
    /// </summary>
    [JsonPropertyName("data")]
    public WebPayDataDto? Data { get; set; }

    /// <summary>
    /// 支付请求URL
    /// </summary>
    [JsonPropertyName("requestPay")]
    public string RequestPay { get; set; } = string.Empty;

    /// <summary>
    /// 提示信息
    /// </summary>
    [JsonPropertyName("tips")]
    public string Tips { get; set; } = string.Empty;
}

/// <summary>
/// Web支付数据DTO
/// </summary>
public class WebPayDataDto
{
    /// <summary>
    /// 订单号
    /// </summary>
    [JsonPropertyName("order_num")]
    public string OrderNum { get; set; } = string.Empty;
}

/// <summary>
/// 发货记录DTO
/// </summary>
public class SendRecordDto
{
    /// <summary>
    /// 发货记录ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 发货单号
    /// </summary>
    [JsonPropertyName("send_num")]
    public string SendNum { get; set; } = string.Empty;

    /// <summary>
    /// 收货人姓名
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 收货人手机号（脱敏）
    /// </summary>
    [JsonPropertyName("mobile")]
    public string Mobile { get; set; } = string.Empty;

    /// <summary>
    /// 收货地址
    /// </summary>
    [JsonPropertyName("address")]
    public string Address { get; set; } = string.Empty;

    /// <summary>
    /// 状态：0=待支付，1=待发货，2=已发货，3=已签收，4=已取消
    /// </summary>
    [JsonPropertyName("status")]
    public int Status { get; set; }

    /// <summary>
    /// 状态名称
    /// </summary>
    [JsonPropertyName("status_name")]
    public string StatusName { get; set; } = string.Empty;

    /// <summary>
    /// 发货数量
    /// </summary>
    [JsonPropertyName("count")]
    public int Count { get; set; }

    /// <summary>
    /// 运费
    /// </summary>
    [JsonPropertyName("freight")]
    public string Freight { get; set; } = "0.00";

    /// <summary>
    /// 创建时间
    /// </summary>
    [JsonPropertyName("addtime")]
    public string AddTime { get; set; } = string.Empty;

    /// <summary>
    /// 快递单号
    /// </summary>
    [JsonPropertyName("courier_number")]
    public string? CourierNumber { get; set; }

    /// <summary>
    /// 快递公司名称
    /// </summary>
    [JsonPropertyName("courier_name")]
    public string? CourierName { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    [JsonPropertyName("user_id")]
    public int UserId { get; set; }

    /// <summary>
    /// 奖品列表
    /// </summary>
    [JsonPropertyName("order_list")]
    public List<SendRecordItemDto>? OrderList { get; set; }
}

/// <summary>
/// 发货记录详情DTO
/// </summary>
public class SendRecordDetailDto
{
    /// <summary>
    /// 发货记录ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 发货单号
    /// </summary>
    [JsonPropertyName("send_num")]
    public string SendNum { get; set; } = string.Empty;

    /// <summary>
    /// 收货人姓名
    /// </summary>
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 收货人手机号
    /// </summary>
    [JsonPropertyName("mobile")]
    public string Mobile { get; set; } = string.Empty;

    /// <summary>
    /// 收货地址
    /// </summary>
    [JsonPropertyName("address")]
    public string Address { get; set; } = string.Empty;

    /// <summary>
    /// 留言备注
    /// </summary>
    [JsonPropertyName("message")]
    public string? Message { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    [JsonPropertyName("status")]
    public int Status { get; set; }

    /// <summary>
    /// 发货数量
    /// </summary>
    [JsonPropertyName("count")]
    public int Count { get; set; }

    /// <summary>
    /// 运费
    /// </summary>
    [JsonPropertyName("freight")]
    public string Freight { get; set; } = "0.00";

    /// <summary>
    /// 创建时间
    /// </summary>
    [JsonPropertyName("addtime")]
    public string AddTime { get; set; } = string.Empty;

    /// <summary>
    /// 支付时间
    /// </summary>
    [JsonPropertyName("pay_time")]
    public string PayTime { get; set; } = string.Empty;

    /// <summary>
    /// 发货时间
    /// </summary>
    [JsonPropertyName("send_time")]
    public string SendTime { get; set; } = string.Empty;

    /// <summary>
    /// 签收时间
    /// </summary>
    [JsonPropertyName("shou_time")]
    public string ShouTime { get; set; } = string.Empty;

    /// <summary>
    /// 快递单号
    /// </summary>
    [JsonPropertyName("courier_number")]
    public string? CourierNumber { get; set; }

    /// <summary>
    /// 快递公司名称
    /// </summary>
    [JsonPropertyName("courier_name")]
    public string? CourierName { get; set; }

    /// <summary>
    /// 奖品列表
    /// </summary>
    [JsonPropertyName("goods")]
    public List<SendRecordItemDto>? Goods { get; set; }
}

/// <summary>
/// 发货记录奖品项DTO
/// </summary>
public class SendRecordItemDto
{
    /// <summary>
    /// 订单详情ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 奖品标题
    /// </summary>
    [JsonPropertyName("goodslist_title")]
    public string GoodsListTitle { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片
    /// </summary>
    [JsonPropertyName("goodslist_imgurl")]
    public string GoodsListImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 奖品回收金额
    /// </summary>
    [JsonPropertyName("goodslist_money")]
    public string GoodsListMoney { get; set; } = "0.00";

    /// <summary>
    /// 赏品等级ID
    /// </summary>
    [JsonPropertyName("shang_id")]
    public int ShangId { get; set; }

    /// <summary>
    /// 赏品等级标题
    /// </summary>
    [JsonPropertyName("shang_title")]
    public string? ShangTitle { get; set; }

    /// <summary>
    /// 奖品数量
    /// </summary>
    [JsonPropertyName("prize_num")]
    public int PrizeNum { get; set; } = 1;

    /// <summary>
    /// 发货状态
    /// </summary>
    [JsonPropertyName("fh_status")]
    public int FhStatus { get; set; }
}

/// <summary>
/// 回收记录DTO
/// </summary>
public class RecoveryRecordDto
{
    /// <summary>
    /// 回收记录ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 回收单号
    /// </summary>
    [JsonPropertyName("recovery_num")]
    public string RecoveryNum { get; set; } = string.Empty;

    /// <summary>
    /// 回收金额
    /// </summary>
    [JsonPropertyName("money")]
    public string Money { get; set; } = "0.00";

    /// <summary>
    /// 回收数量
    /// </summary>
    [JsonPropertyName("count")]
    public int Count { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [JsonPropertyName("addtime")]
    public string AddTime { get; set; } = string.Empty;

    /// <summary>
    /// 奖品列表
    /// </summary>
    [JsonPropertyName("order_list")]
    public List<RecoveryRecordItemDto>? OrderList { get; set; }
}

/// <summary>
/// 回收记录奖品项DTO
/// </summary>
public class RecoveryRecordItemDto
{
    /// <summary>
    /// 订单详情ID
    /// </summary>
    [JsonPropertyName("id")]
    public int Id { get; set; }

    /// <summary>
    /// 奖品标题
    /// </summary>
    [JsonPropertyName("goodslist_title")]
    public string GoodsListTitle { get; set; } = string.Empty;

    /// <summary>
    /// 奖品图片
    /// </summary>
    [JsonPropertyName("goodslist_imgurl")]
    public string GoodsListImgUrl { get; set; } = string.Empty;

    /// <summary>
    /// 奖品回收金额
    /// </summary>
    [JsonPropertyName("goodslist_money")]
    public string GoodsListMoney { get; set; } = "0.00";
}

/// <summary>
/// 物流信息DTO
/// </summary>
public class LogisticsDto
{
    /// <summary>
    /// 快递单号
    /// </summary>
    [JsonPropertyName("courier_number")]
    public string? CourierNumber { get; set; }

    /// <summary>
    /// 快递公司名称
    /// </summary>
    [JsonPropertyName("courier_name")]
    public string? CourierName { get; set; }

    /// <summary>
    /// 快递公司编码
    /// </summary>
    [JsonPropertyName("courier_code")]
    public string? CourierCode { get; set; }

    /// <summary>
    /// 发货数量
    /// </summary>
    [JsonPropertyName("count")]
    public int Count { get; set; }

    /// <summary>
    /// 发货单号
    /// </summary>
    [JsonPropertyName("send_num")]
    public string? SendNum { get; set; }

    /// <summary>
    /// 奖品图片URL
    /// </summary>
    [JsonPropertyName("goodslist_imgurl")]
    public string? GoodsListImgUrl { get; set; }

    /// <summary>
    /// 物流状态描述
    /// </summary>
    [JsonPropertyName("delivery_status")]
    public string DeliveryStatus { get; set; } = "暂无物流轨迹";

    /// <summary>
    /// 物流轨迹列表
    /// </summary>
    [JsonPropertyName("delivery_list")]
    public List<LogisticsTraceDto>? DeliveryList { get; set; }
}

/// <summary>
/// 物流轨迹DTO
/// </summary>
public class LogisticsTraceDto
{
    /// <summary>
    /// 时间
    /// </summary>
    [JsonPropertyName("time")]
    public string Time { get; set; } = string.Empty;

    /// <summary>
    /// 描述/状态
    /// </summary>
    [JsonPropertyName("status")]
    public string Status { get; set; } = string.Empty;
}

#endregion
