namespace ZB.MOM.WW.MxGateway.Server.Security.Authentication;

public sealed record ApiKeyConstraints(
    IReadOnlyList<string> ReadSubtrees,
    IReadOnlyList<string> WriteSubtrees,
    IReadOnlyList<string> ReadTagGlobs,
    IReadOnlyList<string> WriteTagGlobs,
    int? MaxWriteClassification,
    IReadOnlyList<string> BrowseSubtrees,
    bool ReadAlarmOnly,
    bool ReadHistorizedOnly)
{
    public static ApiKeyConstraints Empty { get; } = new(
        ReadSubtrees: Array.Empty<string>(),
        WriteSubtrees: Array.Empty<string>(),
        ReadTagGlobs: Array.Empty<string>(),
        WriteTagGlobs: Array.Empty<string>(),
        MaxWriteClassification: null,
        BrowseSubtrees: Array.Empty<string>(),
        ReadAlarmOnly: false,
        ReadHistorizedOnly: false);

    public bool IsEmpty =>
        ReadSubtrees.Count == 0
        && WriteSubtrees.Count == 0
        && ReadTagGlobs.Count == 0
        && WriteTagGlobs.Count == 0
        && MaxWriteClassification is null
        && BrowseSubtrees.Count == 0
        && !ReadAlarmOnly
        && !ReadHistorizedOnly;

    public bool HasReadConstraints =>
        ReadSubtrees.Count > 0
        || ReadTagGlobs.Count > 0
        || ReadAlarmOnly
        || ReadHistorizedOnly;

    public bool HasWriteConstraints =>
        WriteSubtrees.Count > 0
        || WriteTagGlobs.Count > 0
        || MaxWriteClassification is not null;
}
