namespace OpenWarehouse.warehouse.api.Common.Warehouse;

public static class WarehouseClaimsTypeClass
{
    private static Dictionary<WarehouseClaimsType, string> _warehouseClaimsString = new()
    {
        { WarehouseClaimsType.Company, "Company" },
        { WarehouseClaimsType.Email, "Email" },
        { WarehouseClaimsType.Phone, "Phone" },
        { WarehouseClaimsType.OwnerId, "OwnerID" },
        { WarehouseClaimsType.OwnerUsername, "OwnerUsername" },
        { WarehouseClaimsType.WarehouseAdmin, "WarehouseManagePrivilage" },
        { WarehouseClaimsType.WarehouseManageInfo, "WarehouseManagePrivilageInfo" },
        { WarehouseClaimsType.WarehousePrivilageManage, "WarehouseAdminPrivilage" }
    };

    public static string ToString(this WarehouseClaimsType warehouseClaimsType)
    {
        var result = _warehouseClaimsString.TryGetValue(warehouseClaimsType, out var claim);
        if (!result) throw new NotImplementedException("Claim tyoe not implemented");
        return claim ?? throw new NotImplementedException("Claim tyoe not implemented");
    }

    public static Claim ToClaim(this WarehouseClaimsType warehouseClaimsType, string value, string? issuer = null)
    {
        var result = _warehouseClaimsString.TryGetValue(warehouseClaimsType, out var claim);
        if (!result || claim == null) throw new NotImplementedException("Claim tyoe not implemented");

        if (issuer != null)
        {
            return new Claim(claim, value);
        }
        else
        {
            return new Claim(claim, value, issuer);
        }
        
    }
}