package com.tzy.framework.express.dto;

import com.tzy.common.utils.AddressResolutionUtil;
import com.tzy.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.time.LocalDateTime;

/**
 * 顺丰 运单信息请求体
 */
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SfParamDto {
    //货物名称
    private String goodsName;
    //客户订单号（不可重复）
    private String orderCode;
    //快递类型，261 顺电通产品 1 特快
    private String expressType;
    //收件人城市
    private String receiverCity;
    //收件人公司名称 - 否
    private String receiverCompanyName;
    //收件人详细地址
    private String receiverDetailAddress;
    //收件人姓名
    private String receiverName;
    //收件人电话 - 否
    private String receiverPhone;
    //收件人省份
    private String receiverProvince;
    //收件人手机号
    private String receiverTelephone;
    //寄件人城市
    private String senderCity;
    //寄件人公司名称不能为空
    private String senderCompanyName;
    //寄件人详细地址
    private String senderDetailAddress;
    //寄件人姓名
    private String senderName;
    //寄件人电话 - 否
    private String senderPhone;
    //寄件人省份
    private String senderProvince;
    //寄件人手机号
    private String senderTelephone;
    //要求快递员上门取件时间,LocalDateTime
    private String requiredReceiveGoodsTime;

    /**
     *
     * @param goodsName 货物名称
     * @param orderCode 客户订单号（不可重复）
     */
    public SfParamDto(String goodsName,String orderCode,String expressType){
        this.goodsName= goodsName;
        this.orderCode= orderCode;
        this.expressType= expressType;
    }

    /**
     *
     * @param receiverName 收件人姓名
     * @param receiverTelephone 收件人手机号
     * @param receiverDetailAddress 收件人详细地址
     * @return
     */
    public SfParamDto addReceiverInfo(String receiverName, String receiverTelephone, String receiverDetailAddress, LocalDateTime receiveTime){
        this.receiverName = receiverName;
        this.receiverTelephone = receiverTelephone;
        this.receiverDetailAddress = receiverDetailAddress;
        AddressResolutionUtil addressResolutionUtil = AddressResolutionUtil.addressResolution(receiverDetailAddress);
        this.receiverCity = addressResolutionUtil.getCity();
        this.receiverProvince = StringUtils.isNotEmpty(addressResolutionUtil.getProvince())? addressResolutionUtil.getProvince(): receiverCity;
        this.requiredReceiveGoodsTime = null == receiveTime ? null : receiveTime.toString();
        return this;
    }

    /**
     *
     * @param senderCompanyName 寄件人公司名称不能为空
     * @param senderName 寄件人姓名
     * @param senderTelephone 寄件人手机号
     * @param senderDetailAddress 寄件人详细地址
     * @return
     */
    public SfParamDto addSenderInfo(String senderCompanyName,String senderName,String senderTelephone,String senderDetailAddress){
        this.senderCompanyName = senderCompanyName;
        this.senderName = senderName;
        this.senderTelephone = senderTelephone;
        this.senderDetailAddress = senderDetailAddress;
        AddressResolutionUtil addressResolutionUtil = AddressResolutionUtil.addressResolution(senderDetailAddress);
        this.senderCity = addressResolutionUtil.getCity();
        this.senderProvince = StringUtils.isNotEmpty(addressResolutionUtil.getProvince()) ? addressResolutionUtil.getProvince() : senderCity;
        return this;
    }
}
