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

import com.airlock.iam.base.api.domain.model.identity.Identity;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import jakarta.ws.rs.ext.ParamConverter;
import jakarta.ws.rs.ext.ParamConverterProvider;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class IdentityParamConverterProvider implements ParamConverterProvider {
   @Nullable
   @SuppressFBWarnings("BC_UNCONFIRMED_CAST")
   public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
      return rawType.equals(Identity.class) ? new IdentityParamConverter(((ParameterizedType)genericType).getActualTypeArguments()[0]) : null;
   }
}
