using CashLineERP.Domain.Common;

namespace CashLineERP.Domain.Identity;

public sealed class AccountingOfficeClientAssignment : Entity
{
    public long Id { get; private set; }

    public long AccountingOfficeUserId { get; private set; }

    public long ClientPartyId { get; private set; }

    public bool IsActive { get; private set; } = true;

    public DateTime? RevokedAtUtc { get; private set; }

    public long? RevokedByUserId { get; private set; }

    public ApplicationUser? AccountingOfficeUser { get; private set; }

    public AccountingOfficeClientAssignment(long accountingOfficeUserId, long clientPartyId, long? createdByUserId)
    {
        AccountingOfficeUserId = accountingOfficeUserId;
        ClientPartyId = clientPartyId;
        CreatedByUserId = createdByUserId;
    }

    private AccountingOfficeClientAssignment()
    {
    }

    public void Reinstate(long? actorUserId)
    {
        IsActive = true;
        RevokedAtUtc = null;
        RevokedByUserId = null;
        Touch(actorUserId);
    }

    public void Revoke(long? actorUserId)
    {
        IsActive = false;
        RevokedAtUtc = DateTime.UtcNow;
        RevokedByUserId = actorUserId;
        Touch(actorUserId);
    }
}
