package jnpf.model.personnels.dto.authoritys;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jnpf.model.personnels.po.FtbPersonnelsPermissions;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

@Data
public class FtbAddNewPermissionsDTO {
    /**
     * 用户id
     */
    @NotBlank(message = "用户id不能为空")
    private String userId;

    /**
     * 用户姓名
     */
    @NotBlank(message = "用户姓名不能为空")
    private String userName;

    /**
     * 手机号码
     */
    private String phone;

    /**
     * 员工id(页面显示用，后端处理，前端不传)
     */
    private String userCustomId;

    /**
     * 权限适用范围,0所在组织和下级组织员工,1所在组织员工,2仅下属，3指定组织
     */
    @NotNull(message = "权限适用范围必填")
    private Integer scopePermission;

    /**
     * 指定组织id集合
     */
    private String specifyOrgIds;
    /**
     * 勾选的功能权限id集合
     */
    @NotNull(message = "请勾选功能权限")
    @Size(min = 1, message = "请勾选功能权限")
    @Valid
    private List<@NotBlank(message = "权限id为空") String> permissionIds;

    @JsonIgnore
    private Integer permissionType;

    /**
     * 职等名称集合
     */
    private String postRankNames;

    /**
     * 组织名称集合
     */
    private String orgNames;

    /**
     * 岗位名称集合
     */
    private String postNames;
    /**
     * 组织id集合，多条逗号隔开
     */
    private String orgIds;
    /**
     * 岗位id集合，多条逗号隔开
     */
    private String postIds;
    /**
     * 职等id集合，多条逗号隔开
     */
    private String postRankIds;

    public static FtbPersonnelsPermissions convertFtbPersonnelsPermissions(FtbAddNewPermissionsDTO ftbAddNewPermissionsDTO) {
        if (ftbAddNewPermissionsDTO == null) {
            return null;
        }
        FtbPersonnelsPermissions ftbPersonnelsPermissions = new FtbPersonnelsPermissions();
        ftbPersonnelsPermissions.setUserId(ftbAddNewPermissionsDTO.getUserId());
        ftbPersonnelsPermissions.setUserName(ftbAddNewPermissionsDTO.getUserName());
        ftbPersonnelsPermissions.setPhone(ftbAddNewPermissionsDTO.getPhone());
        ftbPersonnelsPermissions.setUserCustomId(ftbAddNewPermissionsDTO.getUserCustomId());
        ftbPersonnelsPermissions.setScopePermission(ftbAddNewPermissionsDTO.getScopePermission());
        ftbPersonnelsPermissions.setPermissionType(ftbAddNewPermissionsDTO.getPermissionType());
        ftbPersonnelsPermissions.setPostNames(ftbAddNewPermissionsDTO.getPostNames());
        ftbPersonnelsPermissions.setOrgNames(ftbAddNewPermissionsDTO.getOrgNames());
        ftbPersonnelsPermissions.setPostRankNames(ftbAddNewPermissionsDTO.getPostRankNames());
        ftbPersonnelsPermissions.setPostIds(ftbAddNewPermissionsDTO.getPostIds());
        ftbPersonnelsPermissions.setPostRankIds(ftbAddNewPermissionsDTO.getPostRankIds());
        ftbPersonnelsPermissions.setOrgIds(ftbAddNewPermissionsDTO.getOrgIds());
        ftbPersonnelsPermissions.setSpecifyOrgIds(ftbAddNewPermissionsDTO.getSpecifyOrgIds());
        return ftbPersonnelsPermissions;
    }

}
