namespace OpenWarehouse.warehouse.api.Common.Item;

public static class ItemClaimsTypeClass
{
    private static readonly Dictionary<ItemClaimsType, string> ItemClaimType = new()
    {
        { ItemClaimsType.Exp, "Exp" },
        { ItemClaimsType.DateOfProduction, "Date_of_production" },
        { ItemClaimsType.Price, "Price" },
        { ItemClaimsType.Description, "Description" },
        { ItemClaimsType.ManufactoreContry, "Manufactore_Country" },
    };
    
    public static string GetName(this ItemClaimsType itemClaim)
    {
        var result = ItemClaimType.TryGetValue(itemClaim, out var name);

        if (!result || name == null) throw new Exception("Key not found");

        return name;
    }

    public static Claim GerClaims(this ItemClaimsType itemClaim, string value, string? issuer = null)
    {
        var result = ItemClaimType.TryGetValue(itemClaim, out var name);

        if (!result || name == null) throw new Exception("Key not found");

        Claim claim;

        if (issuer != null) claim = new Claim(name, value, issuer);
        else claim = new Claim(name, value);

        return claim;
    }

    public static List<string> GetAllClaimName()
    {
        return ItemClaimType
            .Select(q => q.Value)
            .ToList();
        
    }

    public static bool IsDefaultClaimType(string val)
    {
        var res = ItemClaimType
            .Any(q => q.Value == val);

        return res;
    }
}