package cn.novalon.manage.sys.core.command;

import cn.novalon.manage.common.exception.ErrorCode;
import cn.novalon.manage.common.exception.ValidationException;
import cn.novalon.manage.common.util.StatusConstants;

/**
 * 创建角色命令对象
 * 
 * @author 张翔
 * @date 2026-03-13
 */
public record CreateRoleCommand(
        String roleName,
        String roleKey,
        Integer roleSort,
        Integer status
) {
    public static CreateRoleCommand of(String roleName, String roleKey, Integer roleSort, Integer status) {
        validateStatus(status);
        return new CreateRoleCommand(roleName, roleKey, roleSort, status);
    }

    private static void validateStatus(Integer status) {
        if (status != null && status != StatusConstants.ENABLED && status != StatusConstants.DISABLED) {
            throw new ValidationException(ErrorCode.VALIDATION_INVALID_VALUE, 
                    "Invalid status value. Status must be 0 (disabled) or 1 (enabled)");
        }
    }
}
