package cn.pluss.platform.dto;

import cn.pluss.platform.entity.MerchantBaseInfo;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.util.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author yuchen
 * 
 * @Description 
 */
@Data
public class BusinessLicenseDTO {
	
	@ApiModelProperty(value="当前用户的userId")
	private Long userId;
	
	@ApiModelProperty(value="商户类型")
	private String  merchantType;
	
	@ApiModelProperty(value="营业执照号码")
	private String bussAuthNum;
	
	@ApiModelProperty(value="营业执照名称/商户名称")
	private String bussAuthName;
	
	@ApiModelProperty(value="营业执照上的名字")
	private String principalPerson;
	
	@ApiModelProperty(value="营业执照上的地址/注册地址")
	private String bussAuthAddress;
	
	@ApiModelProperty(value="营业执照注册开始时间")
	private String bussAuthStartTime;
	
	@ApiModelProperty(value="营业执照有效期结束时间")
	private String bussAuthEndTime;
	
	@ApiModelProperty(value="营业执照地址")
	private String businessLicensePic;

	@ApiModelProperty(value="营业执照是否长期有效 0短期 1长期")
	private String type;

	public MerchantBaseInfo convertBusinessLicenseDTO() {
		MsgException.checkBlank(bussAuthNum, "请输入营业执照号");
		MsgException.checkBlank(bussAuthName, "请输入营业执照上的名称");
		MsgException.checkBlank(principalPerson, "请输入营业执照上的名字");
		MsgException.checkBlank(bussAuthAddress, "请输入注册地址");
		MsgException.checkBlank(bussAuthStartTime, "请选择营业执照注册开始时间");
		MsgException.checkBlank(type, "请选择营业执照是否长期");
		MsgException.checkBlank(businessLicensePic, "请上传营业执照");
		
		if("0".equals(type) && StringUtil.isEmpty(bussAuthEndTime)) {
			throw new MsgException("请选择营业执照有效期结束时间，若长期有效则选择2099-12-30");
		}
		
		MerchantBaseInfo merchantBaseInfo = new MerchantBaseInfo();
		merchantBaseInfo.setBussAuthNum(bussAuthNum);
		merchantBaseInfo.setBussAuthName(bussAuthName);
		merchantBaseInfo.setMerchantName(bussAuthName);
		merchantBaseInfo.setPrincipalPerson(principalPerson);
		merchantBaseInfo.setBussAuthAddress(bussAuthAddress);
		merchantBaseInfo.setBussAuthStartTime(bussAuthStartTime);
		if("1".equals(type)) {
			merchantBaseInfo.setBussAuthEndTime("2099-12-30");
		}else if("0".equals(type)){
			merchantBaseInfo.setBussAuthEndTime(bussAuthEndTime);
		}
		merchantBaseInfo.setUserId(userId + "");
		merchantBaseInfo.setBuslicType(type);
		return merchantBaseInfo;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}

