package jnpf.model.franchisee.req;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
 * 简单新增加盟商请求参数
 */
@Data
public class FranchiseeSimpleAddReq implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 加盟商编码
     */
    @NotBlank(message = "加盟商编码不能为空")
    @Length(max = 50, message = "加盟商编码长度不能超过50")
    private String franchiseeCode;

    /**
     * 加盟商名称
     */
    @NotBlank(message = "加盟商名称不能为空")
    @Length(max = 50, message = "加盟商名称长度不能超过50")
    private String franchiseeName;

    /**
     * 联系方式
     */
    @NotBlank(message = "联系方式不能为空")
    @NumberFormat(style = NumberFormat.Style.NUMBER)
    @Length(max = 11, min = 11 ,message = "联系方式长度必须11位")
    private String mobilePhone;

    /**
     * 身份证号
     */
    @Length(max = 50, message = "身份证号长度不能超过50")
    private String idCardNumber;

    /**
     * 加盟日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date joinDate;

    /**
     * 现住址
     */
    @Length(max = 100, message = "现住址长度不能超过100")
    private String currentAddress;

    /**
     * 转换为完整新增请求参数
     *
     * @return 新增请求参数
     */
    public FranchiseeAddReq convert() {
        FranchiseeAddReq addReq = new FranchiseeAddReq();
        addReq.setFranchiseeCode(trim(this.franchiseeCode));
        addReq.setFranchiseeName(trim(this.franchiseeName));
        addReq.setMobilePhone(trim(this.mobilePhone));
        addReq.setIdCardNumber(trim(this.idCardNumber));
        addReq.setJoinDate(this.joinDate);
        addReq.setCurrentAddress(trim(this.currentAddress));
        return addReq;
    }

    private String trim(String value) {
        return value == null ? null : value.trim();
    }
}
