// Copyright © Selmo Technology GmbH. All Rights Reserved

using Microsoft.AspNetCore.Authentication;
using System.Security.Claims;

namespace SelmoStudio.Hmi.Server.Db.Authentication.Service
{
    public class CustomClaimsTransformation : IClaimsTransformation
    {
        public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
        {
            if (!principal.HasClaim(claim => claim.Type == WellKnownClaimTypes.Permission))
            {
                return Task.FromResult(principal);
            }

            ClaimsIdentity claimsIdentity = new ClaimsIdentity();
            var permReadHistoryValue = new Claim(WellKnownClaimTypes.Permission, WellKnownPermissionClaims.ReadHistoryValue);
            claimsIdentity.AddClaim(permReadHistoryValue);

            principal.AddIdentity(claimsIdentity);

            return Task.FromResult(principal);
        }
    }
}