package com.chushang.inspection.work.dto;

import com.chushang.inspection.work.enums.BankBranchesEnum;
import com.chushang.inspection.work.enums.TerminalTypeOperation;
import com.chushang.inspection.work.po.WrkIcbcJs;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DispatchDTO implements Serializable {



    /**
     * 部门id
     */
    private Long deptId;

    /**
     * 商户id
     */
    private Long storeId;

    /**
     * 任务id
     */
    private Long taskId;

    /**
     * 下级任务id
     */
    private Long lowerTaskId;

    /**
     * 商户编号
     */
    private String storeNo;

    /**
     * 商户名称
     */
    private String storeName;

    /**
     * 商户联系人
     */
    private String storeContact;

    /**
     * 商户联系电话
     */
    private String storePhone;

    /**
     * 商户地址
     */
    private String storeAddress;

    /**
     * 商户特殊编号
     */
    private String specialNum;

    /**
     * 门店名称
     */
    private String shopName;

    /**
     * 建档日期
     */
    private LocalDate registerTime;

    /**
     * 商户类型
     */
    private Integer storeType;

    /**
     * 现有其他收单产品
     */
    private String products;

    /**
     * 商户提示工具
     */
    private String tipTool;

    /**
     * 操作员编号
     */
    private String userId;

    /**
     * 巡检频次
     */
    private Integer insFre;

    /**
     * 客户经理
     */
    private String accountManager;

    /**
     * 经理电话
     */
    private String accountPhone;

    /**
     * 注册地址
     */
    private String registerAddress;

    /**
     * 法人/负责人
     */
    private String legalName;

    /**
     * 主键
     */
    private Long terminalId;

    /**
     * 终端sn号
     */
    private String terminalSn;

    /**
     * 终端编号
     */
    private String terminalNo;

    /**
     * 终端类型
     */
    private Integer terminalType;

    /**
     * 终端型号
     */
    private String terminalModel;

    /**
     * 终端版本号
     */
    private String terminalVersion;

    /**
     * 终端地址
     */
    private String terminalAddress;

    /**
     * 终端来源
     */
    private Integer terminalSource;

    /**
     * 地理位置信息
     */
    private String geographicLocation;

    /**
     * 偏差（直线距离 米）
     */
    private Long deviation;

    /**
     * 创建者
     */
    protected String createBy;

    /**
     * 创建日期
     */
    protected LocalDateTime createTime;

    public DispatchDTO dispatch(WrkIcbcJs entity) {
        this.terminalId = entity.getTerminalId();
        // todo 此处应当为 江苏工行的部门id
        this.deptId = 200L;
        this.taskId = 1701151817643495425L;
        this.storeId = entity.getStoreId();
        Long lowerTaskId = BankBranchesEnum.getByCode(entity.getArea());
        this.lowerTaskId = lowerTaskId == null ? this.taskId : lowerTaskId;
        this.storeNo = entity.getMerId();
        this.storeName = entity.getMerName();
        this.storeContact = entity.getLinkName();
        this.storePhone = entity.getContactWay();
        this.storeAddress = entity.getMerAddress();
        this.createBy = "zhuguihua";
        this.createTime = LocalDateTime.now();
        this.terminalAddress = entity.getMerAddress();
        this.terminalNo = entity.getTermId();
        this.terminalSn = entity.getDeviceNo();
        this.terminalType = TerminalTypeOperation.valueOfCode(entity.getDeviceType());
        return this;
    }
}
