package jnpf.model.storecertificatephoto.req;

import jnpf.model.storecertificatephoto.po.StoreCertificatePhotoEntity;
import jnpf.util.FtbUtil;
import jnpf.util.RandomUtil;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 门店证件照新增请求参数
 */
@Data
public class StoreCertificatePhotoAddReq implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 证照名称
     */
    @NotBlank(message = "证照名称不能为空")
    @Length(max = 100, message = "证照名称长度不能超过100")
    private String certificateName;

    /**
     * 证照图片数量
     */
    @NotNull(message = "证照图片数量不能为空")
    @Min(value = 0, message = "证照图片数量最少为0")
    @Max(value = 9, message = "证照图片数量最多为9")
    private Integer imageCount;

    /**
     * 是否必须全部上传
     */
    @NotNull(message = "必须全部上传不能为空")
    @Min(value = 0, message = "必须全部上传只能为0或1")
    @Max(value = 1, message = "必须全部上传只能为0或1")
    private Integer requireAllUpload;

    /**
     * 是否增加到期日期
     */
    @NotNull(message = "增加到期日期不能为空")
    @Min(value = 0, message = "增加到期日期只能为0或1")
    @Max(value = 1, message = "增加到期日期只能为0或1")
    private Integer expireDateEnabled;

    /**
     * 到期日期名称
     */
    @Length(max = 100, message = "到期日期名称长度不能超过100")
    private String expireDateName;

    /**
     * 临期提醒时间
     */
    private Integer expiryReminderDays;

    /**
     * 状态
     */
    @NotNull(message = "状态不能为空")
    @Min(value = 0, message = "状态只能为0或1")
    @Max(value = 1, message = "状态只能为0或1")
    private Integer status;

    /**
     * 图片名称列表
     */
    @Valid
    private List<StoreCertificatePhotoItemReq> imageItemList = new ArrayList<>();

    /**
     * 文本名称列表
     */
    @Valid
    private List<StoreCertificatePhotoItemReq> textItemList = new ArrayList<>();

    /**
     * 转换为实体
     *
     * @return 门店证件照实体
     */
    public StoreCertificatePhotoEntity convert() {
        StoreCertificatePhotoEntity entity = new StoreCertificatePhotoEntity();
        entity.setId(FtbUtil.getId());
        entity.setCertificateName(this.certificateName == null ? null : this.certificateName.trim());
        entity.setImageCount(this.imageCount);
        entity.setRequireAllUpload(this.requireAllUpload);
        entity.setExpireDateEnabled(this.expireDateEnabled);
        entity.setExpireDateName(this.expireDateName == null ? null : this.expireDateName.trim());
        entity.setExpiryReminderDays(this.expiryReminderDays);
        entity.setStatus(this.status);
        entity.setEnabledMark(0);
        return entity;
    }
}
