package cn.ey.biz.module.system.controller.admin.abac.vo;

import cn.ey.biz.module.system.framework.rule.RuleDefinition;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;

@Data
public class AbacVo {

    private Long id;

    @Size(max = 200, message = "应用名最长200个字符")
    private String app;

    @Size(max = 500, message = "规则名最长500个字符")
    private String name;

    @Size(max = 1000, message = "菜单最多1000个")
    private List<Long> menus = new ArrayList<>();

    @Size(max = 100, message = "角色最多100个")
    private List<Long> roleIds = new ArrayList<>();

    @Size(max = 100, message = "角色最多100个")
    private List<Long> checkRoles = new ArrayList<>();

    @Valid
    private RuleDefinition rule;

    @Valid
    private Pipe dynamic;

    @Size(max = 100, message = "Rank最多100个")
    private List<String> ranks = new ArrayList<>();

    @Size(max = 100, message = "Region最多100个")
    private List<String> regions = new ArrayList<>();

    @Size(max = 100, message = "MR最多100个")
    private List<String> mr = new ArrayList<>();

    @Size(max = 50, message = "业务线最长50个字符")
    private String sl;

    @Size(max = 50, message = "子业务线最长50个字符")
    private String ssl;

    @Size(max = 50, message = "competency最长50个字符")
    private String competencyCode;

    @Size(max = 50, message = "smu最长50个字符")
    private String smu;

    @Size(max = 100, message = "OU最多100个")
    private List<String> ou = new ArrayList<>();

    @Size(max = 100, message = "BU最多100个")
    private List<String> bu = new ArrayList<>();

    @Max(value = 1, message = "状态只可以是0或1")
    @Min(value = 0, message = "状态只可以是0或1")
    private int status;

    @Max(value = 1, message = "应用场景只可以是0或1")
    @Min(value = 0, message = "应用场景只可以是0或1")
    private Integer scene;

    private ServiceLineConfig config;

    @Size(max = 500, message = "AAD组最长500个字符")
    private String aadGroup;

    @Data
    @Valid
    public static class ServiceLineConfig {
        @Size(max = 20, message = "业务线最多20个")
        private List<List<String>> serviceLine = new ArrayList<>();
    }

    @Data
    @Valid
    public static class Pipe {

        @Size(max = 50, message = "类型最长50个字符")
        private String type;

        @Size(max = 50, message = "条件最长50个字符")
        private String condition;

        @Size(max = 50, message = "验证项最长50个字符")
        private String name;

        @Size(max = 50, message = "操作符最长50个字符")
        private String operator;

        @Size(max = 50, message = "判断值最长50个字符")
        private String value;

        @Size(max = 50, message = "最多50个子条件")
        private List<Pipe> children = new ArrayList<>();
    }
}
