package com.xy.dto;

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

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

@Data
@ApiModel("角色表DTO")
@Accessors(chain = true)
public class SysRoleDto {

    @Data
    @ApiModel
    @Accessors(chain = true)
    public static class SaveOrUpdate {
        @ApiModelProperty(value = "角色ID")
        private Long id;

        @ApiModelProperty(value = "菜单客户端类型，枚举：menu_client_type")
        private String clientType;

        @NotNull(message = "所属系统不可为空")
        @ApiModelProperty(value = "系统", required = true)
        private Long sysId;

        @NotNull(message = "角色标识不可为空")
        @Size(max = 64, min = 2, message = "角色标识长度需要在2-64之间")
        @ApiModelProperty(value = "角色标识", required = true)
        private String code;

        @NotNull(message = "角色名称不能为空")
        @Size(max = 64, min = 2, message = "角色名称长度需要在2-64之间")
        @ApiModelProperty(value = "角色名称", required = true)
        private String name;

        @ApiModelProperty("描述")
        @Size(max = 255, message = "描述不可超过255个字符")
        private String description;

        @ApiModelProperty("状态;true=启用(默认) false=禁用")
        private Boolean status;

        @ApiModelProperty("是否预留角色;true=是 false=否(默认)")
        private Boolean isLeave;

        @ApiModelProperty("菜单ID数组")
        private List<Long> menuIds;
    }

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

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

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

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

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

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


    }

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

        @NotNull(message = "所属系统不可为空")
        @ApiModelProperty(value = "系统")
        private Long sysId;

        @ApiModelProperty(value = "角色标识")
        private String code;

        @ApiModelProperty(value = "角色名称")
        private String name;


        @ApiModelProperty("状态;true=启用(默认) false=禁用")
        private Boolean status;

        @ApiModelProperty("是否预留角色;true=是 false=否(默认)")
        private Boolean isLeave;
    }


    @Data
    @ApiModel
    @Accessors(chain = true)
    public static class UpdateAdminRoleMenu {
        @NotNull(message = "角色菜单可为空")
        @ApiModelProperty(value = "角色菜单", required = true)
        private List<RoleMenuDto> roleMenuList;

    }


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

        @NotNull(message = "角色ID不可为空")
        @ApiModelProperty(value = "角色ID", required = true)
        private Long roleId;

        @NotNull(message = "菜单ID不可为空")
        @ApiModelProperty(value = "菜单ID", required = true)
        private Long menuId;

        @NotNull(message = "系统ID不可为空")
        @ApiModelProperty(value = "系统ID", required = true)
        private Long sysId;

        @NotNull(message = "角色ID不可为空")
        @ApiModelProperty(value = "管理员查询权限;true=管理员查询权限查询某系统所有数据 false=普通查询权限查询某系统自身数据", required = true)
        private Boolean selectAdmin;


    }


}
