using ERPCore.Common.Http;
using ERPCore.Domain.Enums;
using ERPCore.Dtos.Common;
using ERPCore.Dtos.Rbac;

namespace ERPCore.Services.Interfaces;

/// <summary>
/// Role CRUD + permission assignment. AuthHex is the source of truth for Role
/// identity (docs/10 C.9 "shadow user" pattern, applied to Role): every write is
/// forwarded to AuthHex first, then mirrored into the local shadow <c>Role</c> row.
/// Permission assignment is purely local (ERPCore/UI concern, not an AuthHex one).
/// </summary>
public interface IRoleService
{
    Task<PagedResponse<RoleDto>> ListAsync(PageQuery query, EntityStatus? status, CancellationToken ct = default);
    Task<ETagged<RoleDto>?> GetAsync(int roleId, CancellationToken ct = default);
    Task<ETagged<RoleDto>> CreateAsync(CreateRoleRequest request, CancellationToken ct = default);
    Task<ETagged<RoleDto>> UpdateAsync(int roleId, UpdateRoleRequest request, uint expectedRowVersion, CancellationToken ct = default);
    Task SetStatusAsync(int roleId, EntityStatus status, CancellationToken ct = default);
    Task DeleteAsync(int roleId, CancellationToken ct = default);

    Task<RolePermissionsDto> GetPermissionsAsync(int roleId, CancellationToken ct = default);
    Task<RolePermissionsDto> AssignPermissionsAsync(int roleId, AssignRolePermissionsRequest request, CancellationToken ct = default);

    /// <summary>Resolves the nav codes a role (by AuthHex `RoleCode` claim) may see. Used by `GET /auth/me`.</summary>
    Task<MeResponseDto> GetMeAsync(string? roleCode, CancellationToken ct = default);
}
