package com.airlock.iam.oauth2.application.service;

import com.airlock.iam.base.api.domain.model.user.UserId;
import com.airlock.iam.oauth2.api.domain.model.OAuth2ClientId;
import com.airlock.iam.oauth2.domain.model.session.OAuth2ExtendedSession;
import com.airlock.iam.oauth2.domain.model.session.OAuth2ExtendedSessionRepository;
import com.airlock.iam.oauth2.domain.model.session.OAuth2SessionId;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import java.util.Collection;
import java.util.Optional;

public final class OAuth2ExtendedSessionService {
   private final Provider<OAuth2ExtendedSessionRepository> repository;

   @Inject
   public OAuth2ExtendedSessionService(Provider<OAuth2ExtendedSessionRepository> repository) {
      this.repository = repository;
   }

   public Optional<OAuth2ExtendedSession> findOAuth2ExtendedSession(OAuth2SessionId oAuth2SessionId) {
      return ((OAuth2ExtendedSessionRepository)this.repository.get()).findById(oAuth2SessionId);
   }

   public Collection<OAuth2ExtendedSession> findOAuth2ExtendedSessions(UserId userId) {
      return ((OAuth2ExtendedSessionRepository)this.repository.get()).findByUser(userId);
   }

   public Collection<OAuth2ExtendedSession> findOAuth2ExtendedSessions(UserId userId, OAuth2ClientId clientId) {
      return ((OAuth2ExtendedSessionRepository)this.repository.get()).findByUserAndClient(userId, clientId);
   }

   public Optional<OAuth2ExtendedSession> findOAuth2Session(OAuth2SessionId oAuth2SessionId) {
      return ((OAuth2ExtendedSessionRepository)this.repository.get()).findById(oAuth2SessionId);
   }

   public OAuth2ExtendedSession updateCustomAttributes(OAuth2ExtendedSession oAuth2Session) {
      return ((OAuth2ExtendedSessionRepository)this.repository.get()).updateCustomAttributes(oAuth2Session);
   }

   public boolean deleteOAuth2Session(OAuth2SessionId oAuth2SessionId) {
      return ((OAuth2ExtendedSessionRepository)this.repository.get()).delete(oAuth2SessionId);
   }

   public void deleteOAuth2Sessions(Collection<OAuth2SessionId> sessionIds) {
      ((OAuth2ExtendedSessionRepository)this.repository.get()).delete(sessionIds);
   }
}
