package com.sunyard.chsm.model.dto;

import com.sunyard.chsm.model.PageQuery;
import com.sunyard.chsm.model.Subject;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author liulu
 * @since 2024/10/23
 */
public abstract class KeyInfoDTO {

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class Query extends PageQuery {
        private Long appId;
        private String status;
        private String keyType;
    }

    @Data
    public static class KeySave {

        @NotNull(message = "所属应用不能为空")
        private Long applicationId;
        /**
         * 密钥模版编码
         */
        @NotNull(message = "密钥模版不能为空")
        private String keyTemplateCode;
        /**
         * 生成数量
         */
        @NotNull(message = "生成数量不能为空")
        @Max(value = 100, message = "一次最多生成100个密钥")
        private Integer genNumber;
    }

    @Data
    public static class KeyView {
        private Long id;
        private Long applicationId;
        private String appName;
        /**
         * KEY_ID
         */
        private String code;
        private String keyType;
        private String keyTypeText;
        private String keyAlg;
        private Integer keyLength;
        private List<String> keyUsages;
        private String keyUsageText;
        /**
         * 校验算法
         */
        private String checkAlg;
        /**
         * 校验值
         */
        private String checkValue;
        private String status;
        private String statusText;
        /**
         * 生效时间
         */
        private LocalDateTime effectiveTime;
        /**
         * 过期时间
         */
        private LocalDateTime expiredTime;
        private LocalDateTime createTime;
    }

    @Data
    public static class IDs {
        /**
         * 密钥id列表
         */
        @Size(min = 1, max = 100, message = "密钥id列表长度在1-100之间")
        @NotNull(message = "密钥id列表不能为空")
        private List<Long> ids;


    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class KeyUpdate extends IDs {
        /**
         * 新密钥生效时间 yyyy-MM-dd
         */
        private LocalDate effectiveTime;
    }

    @Data
    public static class Backup {
        /**
         * @ignore
         */
        private String keyType;
        /**
         * 开始日期 yyyy-MM-dd
         */
        @NotNull(message = "开始日期不能为空")
        private LocalDate startTime;
        /**
         * 结束日期 yyyy-MM-dd
         */
        @NotNull(message = "结束日期不能为空")
        private LocalDate endTime;

    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class CreateCsr extends Subject {
        /**
         * 密钥id
         */
        @NotNull(message = "密钥id不能为空")
        private Long id;
    }

    @Data
    public static class CreateCSRResp {
        // 证书请求内容
        private String csr;
    }


}
