package com.xy.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xy.utils.PageBean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Data
@Accessors(chain = true)
public class DeviceCreateIdsDto {

    @Data
    @Accessors(chain = true)
    public static class Save {

        @NotNull(message = "deviceType不能为空")
        @ApiModelProperty("设备类型")
        private Integer deviceType;

        @NotBlank(message = "doorType不能为空")
        @ApiModelProperty("门类型")
        private String doorType;

        @NotBlank(message = "createPc不能为空")
        @ApiModelProperty("生成批次号")
        private String createPc;

        @NotNull(message = "num不能为空")
        @Min(value = 1, message = "num不能小于1")
        @Max(value = 500, message = "num不能大于500")
        @ApiModelProperty("生成数量")
        private Integer num;

        @ApiModelProperty("设备二维码商户id")
        private Long deviceQrMercId;
    }

    @Data
    @Accessors(chain = true)
    public static class SaveCustom {

        @NotNull(message = "deviceId不能为空")
        @ApiModelProperty("设备id")
        private Long deviceId;

        @NotNull(message = "deviceType不能为空")
        @ApiModelProperty("设备类型")
        private Integer deviceType;

        @NotBlank(message = "doorType不能为空")
        @ApiModelProperty("门类型")
        private String doorType;

        @NotBlank(message = "createPc不能为空")
        @ApiModelProperty("生成批次号")
        private String createPc;
    }

    @Data
    @Accessors(chain = true)
    public static class Update extends Vo {

        @NotNull(message = "deviceId不能为空")
        @ApiModelProperty("设备编号;唯一ID，10数，年2月2序号6")
        private Long deviceId;

    }

    @Data
    @Accessors(chain = true)
    public static class UpdateBatch extends Vo {

        @NotNull(message = "deviceIds不能为空")
        @ApiModelProperty("设备编号;唯一ID，10数，年2月2序号6")
        private List<Long> deviceIds;
    }

    @Data
    @Accessors(chain = true)
    public static class Page extends Vo {

        @ApiModelProperty("分页对象")
        private PageBean page;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "创建时间-起")
        private LocalDate beginCreateTime;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "创建时间-始")
        private LocalDate endCreateTime;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "绑定时间-起")
        private LocalDate beginBindTime;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "绑定时间-始")
        private LocalDate endBindTime;

        public LocalDateTime getBeginCreateTime() {
            return beginCreateTime == null ? null : beginCreateTime.atTime(0, 0, 0);
        }

        public LocalDateTime getEndCreateTime() {
            return endCreateTime == null ? null : endCreateTime.atTime(23, 59, 59);
        }

        public LocalDateTime getBeginBindTime() {
            return beginBindTime == null ? null : beginBindTime.atTime(0, 0, 0);
        }

        public LocalDateTime getEndBindTime() {
            return endBindTime == null ? null : endBindTime.atTime(23, 59, 59);
        }
    }

    @Data
    @Accessors(chain = true)
    public static class ExportQrCode extends Vo {

        @NotEmpty(message = "deviceIds不能为空")
        @ApiModelProperty(value = "设备id")
        private List<Long> deviceIds;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "创建时间-起")
        private LocalDate beginCreateTime;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "创建时间-始")
        private LocalDate endCreateTime;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "绑定时间-起")
        private LocalDate beginBindTime;

        @JsonFormat(pattern = "yyyy-MM-dd")
        @ApiModelProperty(value = "绑定时间-始")
        private LocalDate endBindTime;

        public LocalDateTime getBeginCreateTime() {
            return beginCreateTime == null ? null : beginCreateTime.atTime(0, 0, 0);
        }

        public LocalDateTime getEndCreateTime() {
            return endCreateTime == null ? null : endCreateTime.atTime(23, 59, 59);
        }

        public LocalDateTime getBeginBindTime() {
            return beginBindTime == null ? null : beginBindTime.atTime(0, 0, 0);
        }

        public LocalDateTime getEndBindTime() {
            return endBindTime == null ? null : endBindTime.atTime(23, 59, 59);
        }
    }

    @Data
    @Accessors(chain = true)
    public static class Vo {

        @ApiModelProperty("设备编号;唯一ID，10数，年2月2序号6")
        private Long deviceId;

        @ApiModelProperty("设备类型")
        private Integer deviceType;

        @ApiModelProperty("门类型")
        private String doorType;

        @ApiModelProperty("绑定状态")
        private Boolean bindState;

        @ApiModelProperty("生成批次号")
        private String createPc;

        @ApiModelProperty("创建人")
        private Long createUserId;

        @ApiModelProperty("创建人名称")
        private String createUserName;

        @ApiModelProperty("绑定时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime bindTime;

        @ApiModelProperty("是否自定义")
        private Boolean isCustom;

        @ApiModelProperty("创建时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime createTime;

        @ApiModelProperty("最后导出二维码时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime lastExportQrCodeTime;

        @ApiModelProperty("设备二维码商户id")
        private Long deviceQrMercId;

        @ApiModelProperty("设备二维码商户名称")
        private String deviceQrMercName;
    }

}
