package com.zsc.edu.gateway.modules.system.dto;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zsc.edu.gateway.modules.system.entity.Authority;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

/**
 * 权限Dto
 * @author zhuang
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AuthorityDto {
    /**
     * 权限名
     */
    @NotBlank(message = "名字不能为空")
    public String name;
    /**
     * 启用状态
     */
    private Boolean enabled = true;
    /**
     * 备注
     */
    private String remark;

    public LambdaUpdateWrapper<Authority> updateWrapper(Long id) {
        LambdaUpdateWrapper<Authority> updateWrapper = new LambdaUpdateWrapper<>();
        return updateWrapper.eq(Authority::getId, id)
                .set(Authority::getName, name)
                .set(StringUtils.hasText(remark), Authority::getRemark, remark);
    }
}
