package com.airlock.iam.common.application.identity;

import com.airlock.iam.base.api.domain.model.Entity;
import com.airlock.iam.base.api.domain.model.identity.Identity;
import com.airlock.iam.common.domain.model.identity.DefaultStringIdentity;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.ws.rs.ext.ParamConverter;
import java.lang.reflect.Type;

public class IdentityParamConverter<E extends Entity<E>> implements ParamConverter<Identity<E>> {
   private final Type entityType;

   public Identity<E> fromString(String value) {
      return DefaultStringIdentity.identity(value, (Class<E>)this.entityType);
   }

   public String toString(Identity<E> value) {
      return value.asString();
   }

   @SuppressFBWarnings(justification = "generated code")
   public IdentityParamConverter(Type entityType) {
      this.entityType = entityType;
   }
}
