package cn.pluss.platform.dto;

import cn.pluss.platform.converter.MerchantBaseInfoConverter;
import cn.pluss.platform.entity.MerchantBaseInfo;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.util.AreaUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author yuchen
 * 
 * @Description
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MerchantBaseInfoDTO {

    private Long id;

    @ApiModelProperty(value = "当前用户的userId")
    private String userId;

    private String merchantName;

    private String merchantType;

    @ApiModelProperty(value = "商户简称")
    private String alias;

    @ApiModelProperty(value = "经营类目编码")
    private String mcc;

    @ApiModelProperty(value = "经营类目名称")
    private String mccName;

    @ApiModelProperty(value = "支付宝账号")
    private String aliAccount;

    @ApiModelProperty(value = "经营内容描述")
    private String productDesc;

    @ApiModelProperty(value = "商家店所在省市区编码")
    private String addressNo;

    @ApiModelProperty(value = "商户地址")
    private String merchantAddress;

    @ApiModelProperty(value = "详细地址")
    private String address;

    @ApiModelProperty(value = "联系人号码")
    private String contactMobile;

    @ApiModelProperty(value = "联系人姓名")
    private String contactName;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "门头照")
    private String storeHeadPic;

    @ApiModelProperty(value = "门店内照片")
    private String storeInsidePic;

    @ApiModelProperty(value = "收银台照片")
    private String cashPic;

    @ApiModelProperty(value = "用户名")
    private String userPhone;

    @ApiModelProperty(value = "密码")
    private String userPassWord;

    public MerchantBaseInfo convertMerchantBaseInfoDTO() {
        MsgException.checkBlank(merchantType, "请选择商户类型");
        MsgException.checkBlank(alias, "请传入商户简称");
        MsgException.checkBlank(mcc, "请传入经营类目编码");
        MsgException.checkBlank(mccName, "请传入经营类目名称");
        MsgException.checkBlank(merchantAddress, "请传入商户地址");
        MsgException.checkBlank(address, "请传入详细地址");
        MsgException.checkBlank(contactMobile, "请传入联系人号码");
        MsgException.checkBlank(contactName, "请传入联系人姓名");
        MsgException.checkBlank(storeHeadPic, "请上传门头照");
        MsgException.checkBlank(storeInsidePic, "请上传门店内照片");
        MsgException.checkBlank(cashPic, "请上传收银台照片");

        MerchantBaseInfo merchantBaseInfo = MerchantBaseInfoConverter.INSTANCE.dto2Domain(this);
        // 传的格式是 省市区  用逗号隔开
        String[] split = merchantAddress.split(",");

        if (split.length == 2) {
            // 市和省同名的情况下传参可能出现的问题
            merchantBaseInfo.setProvince(split[0]);
            merchantBaseInfo.setCity(split[0]);
            merchantBaseInfo.setDistrict(split[1]);
        } else {
            merchantBaseInfo.setProvince(split[0]);
            merchantBaseInfo.setCity(split[1]);
            merchantBaseInfo.setDistrict(split[2]);
        }

        return merchantBaseInfo;
    }
}

