using IamService.Domain.SeedWork;

namespace IamService.Domain.AggregatesModel.AccessReviewAggregate;

/// <summary>
/// EN: Access review item entity - represents a single access to be reviewed.
/// VI: Entity item đánh giá truy cập - đại diện cho một quyền truy cập cần đánh giá.
/// </summary>
public class AccessReviewItem : Entity
{
    private Guid _reviewId;
    private Guid _userId;
    private string _resourceType = null!;
    private Guid _resourceId;
    private string _permission = null!;
    private ReviewDecision _decision;
    private Guid? _reviewedByUserId;
    private DateTime? _reviewedAt;
    private string? _comments;

    public Guid ReviewId => _reviewId;
    public Guid UserId => _userId;
    public string ResourceType => _resourceType;
    public Guid ResourceId => _resourceId;
    public string Permission => _permission;
    public ReviewDecision Decision => _decision;
    public Guid? ReviewedByUserId => _reviewedByUserId;
    public DateTime? ReviewedAt => _reviewedAt;
    public string? Comments => _comments;

    protected AccessReviewItem() 
    { 
        _decision = ReviewDecision.Pending;
    }

    public AccessReviewItem(
        Guid reviewId,
        Guid userId,
        string resourceType,
        Guid resourceId,
        string permission)
    {
        Id = Guid.NewGuid();
        _reviewId = reviewId;
        _userId = userId;
        _resourceType = resourceType;
        _resourceId = resourceId;
        _permission = permission;
        _decision = ReviewDecision.Pending;
    }

    public void Certify(Guid reviewerUserId, string? comments = null)
    {
        _decision = ReviewDecision.Certify;
        _reviewedByUserId = reviewerUserId;
        _reviewedAt = DateTime.UtcNow;
        _comments = comments;
    }

    public void Revoke(Guid reviewerUserId, string? comments = null)
    {
        _decision = ReviewDecision.Revoke;
        _reviewedByUserId = reviewerUserId;
        _reviewedAt = DateTime.UtcNow;
        _comments = comments;
    }
}
