namespace GmRelay.Shared.Domain;

public enum PublicationMode
{
    None,
    Catalog,
    ClubOnly,
    Both
}

public static class PublicationModeExtensions
{
    public const string NoneValue = nameof(PublicationMode.None);
    public const string CatalogValue = nameof(PublicationMode.Catalog);
    public const string ClubOnlyValue = nameof(PublicationMode.ClubOnly);
    public const string BothValue = nameof(PublicationMode.Both);

    public static bool IsVisibleInCatalog(this PublicationMode mode) =>
        mode is PublicationMode.Catalog or PublicationMode.Both;

    public static bool IsVisibleToClubMembers(this PublicationMode mode) =>
        mode is PublicationMode.ClubOnly or PublicationMode.Both;

    public static string ToDatabaseValue(this PublicationMode mode) =>
        mode switch
        {
            PublicationMode.None => NoneValue,
            PublicationMode.Catalog => CatalogValue,
            PublicationMode.ClubOnly => ClubOnlyValue,
            PublicationMode.Both => BothValue,
            _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, "Unknown publication mode.")
        };

    public static PublicationMode FromDatabaseValue(string? value) =>
        value switch
        {
            null or "" => PublicationMode.None,
            NoneValue => PublicationMode.None,
            CatalogValue => PublicationMode.Catalog,
            ClubOnlyValue => PublicationMode.ClubOnly,
            BothValue => PublicationMode.Both,
            _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown publication mode.")
        };
}
