package jnpf.model.authority.dto.role;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import jnpf.model.authority.dto.menu.FtbPermissionMigrareRoleAddDTO;
import jnpf.model.authority.dto.menu.FtbPermissionRoleAddDTO;
import jnpf.model.authority.po.FtbPermissionRole;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;

@EqualsAndHashCode(callSuper = true)
@Data
public class FtbPermissionRoleUpdateDTO extends FtbPermissionRoleAddDTO {
    /**
     * 角色主键id
     */
    @NotBlank(message = "角色主键id不能为空")
    private String roleId;


    public LambdaUpdateWrapper<FtbPermissionRole> update(FtbPermissionRoleUpdateDTO data) {
        return new LambdaUpdateWrapper<FtbPermissionRole>()
                .eq(FtbPermissionRole::getId, data.getRoleId())
                .set(FtbPermissionRole::getRoleName, data.getRoleName())
                .set(FtbPermissionRole::getRoleDescription, data.getRoleDescription());
    }

    public static FtbPermissionRoleUpdateDTO covert(FtbPermissionMigrareRoleAddDTO  data) {
        if (data == null) {
            return null;
        }
        FtbPermissionRoleUpdateDTO ftbPermissionRoleUpdateDTO = new FtbPermissionRoleUpdateDTO();
        ftbPermissionRoleUpdateDTO.setRoleId(data.getRoleId());
        ftbPermissionRoleUpdateDTO.setId(data.getId());
        ftbPermissionRoleUpdateDTO.setRoleName(data.getRoleName());
        ftbPermissionRoleUpdateDTO.setRoleDescription(data.getRoleDescription());
        ftbPermissionRoleUpdateDTO.setPermissionRoleInners(data.getPermissionRoleInners());
        return ftbPermissionRoleUpdateDTO;
    }
}
