namespace CashLineERP.Domain.Identity;

public sealed class FunctionGovernanceDefinition
{
    public long Id { get; private set; }

    public string FunctionCode { get; private set; } = string.Empty;

    public string FunctionLabel { get; private set; } = string.Empty;

    public string MenuSectionCode { get; private set; } = string.Empty;

    public string PortalCode { get; private set; } = string.Empty;

    public string UserTypeCode { get; private set; } = string.Empty;

    public string Route { get; private set; } = string.Empty;

    public string StepId { get; private set; } = string.Empty;

    public string PermissionCode { get; private set; } = string.Empty;

    public string RuleCode { get; private set; } = string.Empty;

    public int DisplayOrder { get; private set; }

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

    public DateTime UpdatedAtUtc { get; private set; }

    public long? UpdatedByUserId { get; private set; }

    public FunctionGovernanceDefinition(
        long id,
        string functionCode,
        string functionLabel,
        string menuSectionCode,
        string portalCode,
        string userTypeCode,
        string route,
        string stepId,
        string permissionCode,
        string ruleCode,
        int displayOrder,
        DateTime updatedAtUtc,
        long? updatedByUserId = null)
    {
        Id = id;
        FunctionCode = functionCode;
        FunctionLabel = functionLabel;
        MenuSectionCode = menuSectionCode;
        PortalCode = portalCode;
        UserTypeCode = userTypeCode;
        Route = route;
        StepId = stepId;
        PermissionCode = permissionCode;
        RuleCode = ruleCode;
        DisplayOrder = displayOrder;
        UpdatedAtUtc = updatedAtUtc;
        UpdatedByUserId = updatedByUserId;
    }

    private FunctionGovernanceDefinition()
    {
    }

    public void Update(string functionLabel, string menuSectionCode, int displayOrder, bool isEnabled, long actorUserId)
    {
        FunctionLabel = functionLabel.Trim();
        MenuSectionCode = menuSectionCode.Trim().ToUpperInvariant();
        DisplayOrder = displayOrder;
        IsEnabled = isEnabled;
        UpdatedAtUtc = DateTime.UtcNow;
        UpdatedByUserId = actorUserId;
    }
}
