using Books.Api.Domain.UserAccess;

namespace Books.Api.EventFlow.ReadModels;

/// <summary>
/// DTO for UserCompanyAccess query results.
/// Maps from database rows via Dapper.
/// </summary>
public class UserCompanyAccessReadModelDto
{
    public string AggregateId { get; set; } = string.Empty;
    public string UserId { get; set; } = string.Empty;
    public string CompanyId { get; set; } = string.Empty;
    public string Role { get; set; } = string.Empty;
    public string GrantedBy { get; set; } = string.Empty;
    public DateTimeOffset GrantedAt { get; set; }
    public bool IsActive { get; set; }
    public DateTimeOffset? RevokedAt { get; set; }
    public string? RevokedBy { get; set; }
    public DateTimeOffset CreateTime { get; set; }
    public DateTimeOffset UpdatedTime { get; set; }

    /// <summary>
    /// Parse the role string to the enum.
    /// </summary>
    public CompanyRole GetRole() => CompanyRoleExtensions.FromDbString(Role);
}
