using MessagePack;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XPrintServer.DataModel.Models
{
    ///<summary>
    ///订单表
    ///</summary>
    [SugarIndex("idx_{split_table}_create_time", nameof(CreateTime), OrderByType.Desc)]
    [SugarIndex("idx_{split_table}_times", [nameof(OrderTime), nameof(RefundStartTime), nameof(RefundTime), nameof(PayTime), nameof(FinishTime)], [OrderByType.Desc, OrderByType.Desc, OrderByType.Desc, OrderByType.Desc, OrderByType.Desc])]
    [SplitTable(SplitType.Year)]//按年分表 （自带分表支持 年、季、月、周、日）
    [SugarTable("order_{year}{month}{day}")]//3个变量必须要有，这么设计为了兼容开始按年，后面改成按月、按日
    public partial class Order
    {
        public Order()
        {
        }

        /// <summary>
        /// Desc:Id
        /// Default:
        /// Nullable:False
        /// </summary>           
        [Key("Id")]
        [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键Id")]
        public Guid Id { get; set; }


        /// <summary>
        /// 订单名称
        /// </summary>
        [Key("OrderName")]
        [SugarColumn(IsNullable = false, ColumnDescription = "订单名称")]
        public string OrderName { get; set; } = null!;


        /// <summary>
        /// 下单用户Id，为Null则为游客
        /// </summary>
        [Key("OrderUserId")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "下单用户Id，为Null则为游客")]
        public Guid? OrderUserId { get; set; } = null;


        /// <summary>
        /// 支付类型；1：网银支付；2：支付宝支付；3:微信支付；4：信用卡支付；5:展会订单，不需要支付
        /// </summary>
        [Key("PayType")]
        [SugarColumn(IsNullable = true, DefaultValue = "0", ColumnDescription = "支付类型；1：网银支付；2：支付宝支付；3:微信支付；4：信用卡支付；5:展会订单，不需要支付")]
        public int PayType { get; set; } = 0;


        /// <summary>
        /// 订单状态；1：未支付；2：已支付；3:生产中；4:已生产；5：已发货；6：用户已收到货 7：已完成；8：申请退款中；9：退款中；10：已退款；
        /// </summary>
        [Key("OrderStatus")]
        [SugarColumn(IsNullable = true, DefaultValue = "0", ColumnDescription = "订单状态；1：未支付；2：已支付；3:生产中；4:已生产；5：已发货；6：用户已收到货 7：已完成；8：申请退款中；9：退款中；10：已退款；")]
        public int OrderStatus { get; set; } = 0;


        /// <summary>
        /// 商户订单号
        /// </summary>        
        [Key("OutTradeNo")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "商户订单号")]
        public string? OutTradeNo { get; set; } = null;

        /// <summary>
        /// 商户退款单号
        /// </summary>
        [Key("OutRefundNo")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "商户退款单号")]
        public string? OutRefundNo { get; set; } = null;


        /// <summary>
        /// 下单时间
        /// </summary>
        [Key("OrderTime")]
        [SugarColumn(IsNullable = false, ColumnDescription = "下单时间")]
        public DateTime OrderTime { get; set; }

        /// <summary>
        /// 订单退款发起时间
        /// </summary>
        [Key("RefundStartTime")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "订单退款发起时间")]
        public DateTime? RefundStartTime { get; set; }

        /// <summary>
        /// 订单退款完成时间
        /// </summary>
        [Key("RefundTime")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "订单退款完成时间")]
        public DateTime? RefundTime { get; set; }

        /// <summary>
        /// 订单支付时间
        /// </summary>
        [Key("PayTime")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "订单支付时间")]
        public DateTime? PayTime { get; set; }

        /// <summary>
        /// 订单完成时间
        /// </summary>
        [Key("FinishTime")]
        [SugarColumn(IsNullable = true, DefaultValue = null, ColumnDescription = "订单完成时间")]
        public DateTime? FinishTime { get; set; }


        [Key("CreateTime")]
        [SplitField] //分表字段 在插入的时候会根据这个字段插入哪个表，在更新删除的时候用这个字段找出相关表
        public DateTime CreateTime { get; set; }

    }
}
