"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRolePermissionNames = getRolePermissionNames;
exports.mapRoleToResponse = mapRoleToResponse;
exports.mapRoleToSessionSnapshot = mapRoleToSessionSnapshot;
function getRolePermissionNames(role) {
    const permissions = new Set();
    for (const rolePermission of role?.rolePermissions ?? []) {
        const name = rolePermission?.permission?.name?.trim();
        if (name) {
            permissions.add(name);
        }
    }
    return Array.from(permissions).sort((a, b) => a.localeCompare(b));
}
function mapRoleToResponse(role) {
    return {
        id: role.id,
        name: role.name,
        guard: role.guard,
        isSystem: role.isSystem,
        isActive: role.isActive,
        tenantId: role.tenantId,
        tenant: role.tenant ? { id: role.tenant.id, name: role.tenant.name, slug: role.tenant.slug } : undefined,
        permissions: getRolePermissionNames(role),
        createdAt: role.createdAt,
        updatedAt: role.updatedAt,
    };
}
function mapRoleToSessionSnapshot(role) {
    return {
        id: role.id,
        name: role.name,
        guard: role.guard,
        tenantId: role.tenantId,
        isSystem: role.isSystem,
        isActive: role.isActive,
    };
}
//# sourceMappingURL=role-mapper.util.js.map