package cn.axzo.workflow.common.model.request.category;

import cn.axzo.workflow.common.enums.VarTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CategoryGroupVarUpsertDto {

    @ApiModelProperty(value = "字典id")
    @Min(value = 1, message = "字典id值必须大于等1")
    @NotNull(message = "字典id不能为空")
    private Long dictId;

    @Valid
    private List<CategoryGroupUpsertVo> groupVos;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class CategoryGroupUpsertVo implements Serializable {
        private static final long serialVersionUID = 5406711143425155649L;

        /**
         * id
         */
        private Long id;

        /**
         * 上级分组id
         */
        private Long parentGroupId;

        /**
         * 分组名
         */
        @NotBlank(message = "分组名称不能为空")
        @Length(max = 50, message = "字典标签最长只支持50个字符")
        private String groupName;

        @NotNull(message = "序号不能为空")
        private Integer ordinal;

        @Valid
        private List<CategoryVarUpsertVo> vars;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class CategoryVarUpsertVo implements Serializable {

        private static final long serialVersionUID = -1918203166603971593L;

        private Long id;

        /**
         * 分组id
         */
        private Long groupId;

        /**
         * 变量类型，文本/图片
         */
        @NotNull(message = "变量类型不能为空")
        private VarTypeEnum type;

        /**
         * 变量code
         */
        @NotBlank(message = "变量编码不能为空")
        @Length(max = 50, message = "变量编码最长只支持50个字符")
        @Pattern(regexp = "^[a-zA-Z]+$", message = "变量编码仅限英文字符")
        private String code;

        /**
         * 变量名称
         */
        @NotBlank(message = "变量名称不能为空")
        @Length(max = 50, message = "变量名称最长只支持50个字符")
        private String name;

        @NotNull(message = "序号不能为空")
        private Integer ordinal;
    }
}
