package jnpf.model.authority.dto.menu;

import jnpf.model.authority.po.FtbPermissionFunctionMenu;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @Author: peng.hao
 * @create: 2025/3/11
 */
@Data
public class FtbPermissionFunctionMenuDTO {
    /**
     * 主键id
     */
    String id;
    /**
     * 父级id
     */
    private  String parentId;
    /**
     * 父级编码
     */
    @NotBlank(message = "父级编码不能为空")
    private  String originalCoding;

    @NotBlank(message = "名称不能为空")
    @Length(max = 20, message = "名称不能超过20个字符")
    @Pattern(regexp = "^[\u4e00-\u9fa5a-zA-Z]+$", message = "名称只能是中文和英文")
    private String name;

    @NotBlank(message = "编码不能为空")
    @Length(max = 50, message = "编码不能超过50个字符")
    @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_.]*[a-zA-Z0-9]$|^[a-zA-Z][a-zA-Z0-9]$",
            message = "编码必须以字母开头，可包含字母、数字、下划线和点号，且以字母或数字结尾")
    private String enCode;
    /**
     * 菜单类型,0子页面1按钮
     */
    @NotNull(message = "菜单类型不能为空")
    private Integer funType;

    /**
     * 页面类型,0web菜单1app菜单2pc菜单
     */
    @NotNull(message = "页面类型不能为空")
    private Integer pageType;

    public static FtbPermissionFunctionMenu convert(FtbPermissionFunctionMenuDTO dto) {
        FtbPermissionFunctionMenu entity = new FtbPermissionFunctionMenu();
        entity.setId(dto.getId());
        entity.setParentId(dto.getParentId());
        entity.setFunName(dto.getName());
        entity.setFuncCoding(dto.getEnCode());
        entity.setFunType(dto.getFunType());
        entity.setPageType(dto.getPageType());
        entity.setOriginalCoding(dto.getEnCode());
        return entity;
    }
}
