package com.ghy.order.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import com.ghy.common.enums.OrderStatus;
import com.ghy.common.enums.PayStatus;
import com.ghy.common.enums.PayTypeEnum;
import com.ghy.goods.domain.Goods;
import com.ghy.payment.domain.FinancialMaster;
import com.ghy.worker.domain.Worker;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author clunt
 * 主单表(对应付款订单)
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class OrderMaster extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @Excel(name = "序号", cellType = Excel.ColumnType.NUMERIC)
    private Long id;

    @Excel(name = "商户ID", cellType = Excel.ColumnType.NUMERIC)
    private Long deptId;

    @Excel(name = "订单编码", cellType = Excel.ColumnType.STRING)
    private String code;

    @Excel(name = "消费者用户id", cellType = Excel.ColumnType.NUMERIC)
    private Long customerId;

    @Excel(name = "地址id", cellType = Excel.ColumnType.NUMERIC)
    private Long addressId;

    @Excel(name = "订单类型", cellType = Excel.ColumnType.NUMERIC)
    private Integer orderType;

    /**
     * @see OrderStatus
     */
    @Excel(name = "订单状态", cellType = Excel.ColumnType.NUMERIC)
    private Integer orderStatus;

    /**
     * @see PayTypeEnum
     */
    @Excel(name = "付款类型", cellType = Excel.ColumnType.NUMERIC)
    private Integer payType;

    /**
     * @see PayStatus
     */
    @Excel(name = "付款状态", cellType = Excel.ColumnType.NUMERIC)
    private Integer payStatus;

    private String payStatusList;

    @Excel(name = "接单师傅id", cellType = Excel.ColumnType.NUMERIC)
    private Long workerId;

    @Excel(name = "付款时间", cellType = Excel.ColumnType.STRING)
    private Date payTime;

    @Excel(name = "接单时间", cellType = Excel.ColumnType.STRING)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date revTime;

    private Date expectTimeStart;

    private Date expectTimeEnd;

    private String mixExpectTime;

    private Worker worker;

    private String customerName;

    private String customerPhone;

    private FinancialMaster financialMaster;

    private OrderGoods orderGoods;

    private Long goodsId;

    private Long goodsCategoryId;

    private String goodsName;

    private Long countryId;

    private Integer exceptOrderStatus;

    private String orderStatuses;

    private String orderStatusName;

    private Boolean isOverTime;

    private String orderMasterIds;

    private Boolean useTimeNotRange;

    private Boolean isMonitoredOrder;

    private Integer allSelfAssigned;

    private Boolean resetAllSelfAssigned;

    private Integer hasDispatchedAll;

    private List<Long> customerIds;

    private Boolean shelveStatus;

    private List<Long> exceptOrderMasterIds;

    // 下单总金额
    private BigDecimal financialMasterMoney;

    // 师傅应得金额
    private BigDecimal financialMasterPayMoney;

    private Goods goods;

    /*
    *  后台使用的三级类目*数量 例如 【清洗-电器-空调】x 3
    * */
    private String consoleGoodsName;

    private String addressPhone;

    private String addressName;

    private String address;

    /**
     * 是否超时 1=是 0=否
     */
    private Integer timeout;

    /**
     * 超时扣款次数
     */
    private Integer timeoutFineTimes;

    private String orderMode;

    private String orderImgs;

    private String payMode;

    private String isCharge;

    private String isContact;

    private Integer sysPayStatus;

    /**
     * 是否约单
     * */
    private String isCall;

    private BigDecimal serverMoney;

    private BigDecimal serverGoodsMoney;

    private Boolean searchAfterList;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTimeStart;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTimeEnd;

    private String lastCallTime;

    private List<Long> cityIds;

    private List<Long> districtIds;

    private List<Long> streetIds;

    private List<Long> addressIds;

    private List<Long> orderMasterIdList;

    // 商品品牌 -- 后台发单才有
    private String goodsBrand;
    // 商品规格 -- 后台发单才有
    private String goodsSpecification;

    /**
     *  后台关键字搜索
     * */
    private String keywords;

    private String workerPhone;

    private String workerName;

    private String province;

    private String city;

    private String district;

    private String consultMode;

    private Long insuranceId;

    private Long cityId;

    /*街道id*/
    private Long streetId;

    private Long provinceId;

    private String name;
    private String phone;

    private String provinceName;

    private String cityName;

    private String countryName;

    private String streetName;

    private Integer  withdrawn;

    private Long serverGoodsId;

    private Long goodsOrderMasterId;

    /**
     * 服务店铺ID
     */
    private Long serviceShopId;

    private String trackingNumber;

    /**
     * 是否已派发服务订单：0=未派发，1=已派发
     */
    private Integer hasServiceOrder;

    /**
     * 下单图片
     */
    @Excel(name = "下单图片", cellType = Excel.ColumnType.STRING)
    private String orderImages;

    /**
     * 是否发货到服务店：0=否，1=是
     */
    @Excel(name = "是否发货到服务店", cellType = Excel.ColumnType.NUMERIC)
    private Integer isDeliveryToStore;

    /**
     * 发货类型：1=发快递/物流，2=送货上门，3=自提
     */
    @Excel(name = "发货类型", cellType = Excel.ColumnType.NUMERIC, readConverterExp = "1=发快递/物流,2=送货上门,3=自提")
    private Integer deliveryType;

    /**
     * 发货备注
     */
    @Excel(name = "发货备注", cellType = Excel.ColumnType.STRING)
    private String deliveryRemark;

    /**
     * 发货图片
     */
    @Excel(name = "发货图片", cellType = Excel.ColumnType.STRING)
    private String deliveryImages;

    /**
     * 是否已开票：0=是，1=否
     */
    @Excel(name = "是否已开票", cellType = Excel.ColumnType.NUMERIC, readConverterExp = "0=是,1=否")
    private Integer isInvoiced;

    /**
     * 是否需要开票：0=不需要，1=需要
     */
    @Excel(name = "是否需要开票", cellType = Excel.ColumnType.NUMERIC, readConverterExp = "0=不需要,1=需要")
    private Integer isNeedBill;

    /**
     * 原师傅id（转单前的师傅）
     */
    @Excel(name = "原师傅id", cellType = Excel.ColumnType.NUMERIC)
    private Long originalWorkerId;

    /**
     * 退单原因
     */
    private String returnReason;

    /**
     * 退单原因详情
     */
    private String returnReasonDetail;

    /**
     * 退单图片
     */
    private String returnImages;

    /**
     * 师傅备注
     */
    private String workerRemark;

    /**
     * 售后状态：0-无售后，1-售后纠纷
     */
    @Excel(name = "售后状态：0-无售后，1-售后纠纷,2-售后已完成,3-售后已取消")
    private Integer afterServiceStatus;

    /**
     * 分账倒计时结束时间（workFinishTime + 设置的倒计时字段）
     */
    @Excel(name = "分账倒计时结束时间", cellType = Excel.ColumnType.STRING)
   
    private Date shareAccountCountdownEndTime;

    /**
     * 分账倒计时时长（单位：小时）
     */
    @Excel(name = "分账倒计时时长", cellType = Excel.ColumnType.NUMERIC)
    private Integer shareAccountCountdownDuration;

    /**
     * 是否包含原始工人ID查询（用于orderType=0的情况）
     */
    private Boolean includeOriginalWorker;

    /**
     * 是否显示在监控单：0=不显示，1=显示在监控单
     */
    @Excel(name = "是否显示在监控单", cellType = Excel.ColumnType.NUMERIC, readConverterExp = "0=不显示,1=显示在监控单")
    private Integer showInMonitor;

    /**
     * 是否已撤销服务主单：0=未撤销，1=已撤销
     */
    @Excel(name = "是否已撤销服务主单", cellType = Excel.ColumnType.NUMERIC, readConverterExp = "0=未撤销,1=已撤销")
    private Integer serviceCancelled;

    /**
     * 更新时间别名字段（用于SQL查询中的update_time别名映射）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTimeAlias;


    private String from;

    /**
     * 是否排除商品订单标识（用于Service层过滤逻辑）
     */
    private Boolean excludeGoodsOrder;

    /**
     * 退款时是否已支付：0=未支付，1=已支付
     */
    @Excel(name = "退款时是否已支付", cellType = Excel.ColumnType.NUMERIC, readConverterExp = "0=未支付,1=已支付")
    private Integer refundPayStatus;

    private Integer pageSize;

    private Integer pageNum;

    /**
     * 仅用于前端/接口参数传递：
     * true = 查询结果要展开到当前城市下的所有街道
     * false/null = 保持原样
     */
    private Boolean showAllStreet;
}
