namespace OpenWarehouse.warehouse.api.Common.ServiceClaims;

public static class ServiceClaimsClass
{
    private static readonly Dictionary<ServiceClaim, string> ServiceClaimsMap = new()
    {
        { ServiceClaim.ServiceAcoountToken, "Service_account_token" },
        { ServiceClaim.ServiceAcoountUsername, "Service_account_username" }
    };
    
    public static string GetName(this ServiceClaim serviceClaim)
    {
        var result = ServiceClaimsMap.TryGetValue(serviceClaim, out var name);
        return (result ? name : $"Uknow-{serviceClaim}") ?? $"Role {serviceClaim} Uknow";
    }

    public static Claim GerClaims(this ServiceClaim serviceClaim, string value)
    {
        var result = ServiceClaimsMap.TryGetValue(serviceClaim, out var name);
        if (!result || value == null) throw new Exception("Claims type not implement");

        return new Claim(name ?? throw new NullReferenceException("Claim name excemption"), value);
    }

    public static Data.ServiceClaims CreateServiceClaims(this ServiceClaim serviceClaim, string value)
    {
        return new Data.ServiceClaims() { ClaimType = serviceClaim.GetName(), ClaimValue = value };
    }
}