namespace SQLInsight.Licensing;
public enum LicensePlan
{
Community,
Professional,
Enterprise,
}
///
/// What a license grants. SQLInsight Pro monitors everything without a license; a license adds findings sync to
/// SQLInsight Hub and records the support agreement.
///
public sealed record License
{
public required string LicenseId { get; init; }
public required string Customer { get; init; }
public required LicensePlan Plan { get; init; }
public required DateTimeOffset IssuedAt { get; init; }
public required DateTimeOffset ExpiresAt { get; init; }
/// How many instances may sync findings to the hub. 0 means unlimited.
public int MaxInstances { get; init; }
/// Id of the key that signed the license (for key rotation).
public required string KeyId { get; init; }
public bool IncludesFindingsSync => Plan is LicensePlan.Professional or LicensePlan.Enterprise;
public bool IncludesPrioritySupport => Plan is LicensePlan.Professional or LicensePlan.Enterprise;
public bool IncludesPhoneSupport => Plan is LicensePlan.Enterprise;
}
public enum LicenseState
{
/// No license configured: Community.
None,
Valid,
/// Expired, but within the grace period: everything still works; renew soon.
ExpiredInGrace,
Expired,
/// The signature does not match, the key is unknown, or the text is damaged.
Invalid,
}
public sealed record LicenseStatus(LicenseState State, License? License, string Message)
{
/// Findings may be synced while the license is valid or in grace.
public bool AllowsFindingsSync => State is LicenseState.Valid or LicenseState.ExpiredInGrace && License!.IncludesFindingsSync;
}