package com.airlock.iam.admin.application.service.token.oathotp;

import com.airlock.iam.admin.domain.model.token.oathotp.OathOtpActivationLetter;
import com.airlock.iam.admin.domain.model.token.oathotp.OathOtpActivationLetterOrder;
import com.airlock.iam.base.api.domain.model.exception.ViolationException;
import com.airlock.iam.base.api.domain.model.user.UserId;
import com.airlock.iam.common.domain.model.token.oathotp.OathOtpToken;
import com.airlock.iam.core.misc.impl.tokenverifier.oathotp.OtpCredBeanData;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.inject.Inject;
import java.util.Optional;
import java.util.function.UnaryOperator;

public class AdminTotpTokenServiceImpl implements AdminTotpTokenService {
   private final AdminOathOtpTokenServiceImpl adminOathOtpTokenService;

   @Inject
   public AdminTotpTokenServiceImpl(AdminOathOtpTokenServiceImpl adminOathOtpTokenService) {
      this.adminOathOtpTokenService = adminOathOtpTokenService;
   }

   @Override
   public void resetTimeOffset(UserId userId) {
      UnaryOperator<OtpCredBeanData> update = credBeanData -> {
         credBeanData.setOffset(0L);
         return credBeanData;
      };
      this.adminOathOtpTokenService.updateChallenge(userId, update);
   }

   @Override
   public OathOtpTokenService.OathOtpTokenType getTokenType() {
      return this.adminOathOtpTokenService.getTokenType();
   }

   @Override
   public void unorderActivationLetter(UserId userId) {
      this.adminOathOtpTokenService.unorderActivationLetter(userId);
   }

   @Override
   public void orderActivationLetter(UserId userId) {
      this.adminOathOtpTokenService.orderActivationLetter(userId);
   }

   @Override
   public OathOtpActivationLetterOrder getActivationLetterOrder(UserId userId) {
      return this.adminOathOtpTokenService.getActivationLetterOrder(userId);
   }

   @Override
   public Optional<OathOtpActivationLetter> getActivationLetter(UserId userId) {
      return this.adminOathOtpTokenService.getActivationLetter(userId);
   }

   @Override
   public boolean isAvailableForAdministration(UserId userId) {
      return this.adminOathOtpTokenService.isAvailableForAdministration(userId);
   }

   @Override
   public boolean hasToken(UserId userId) {
      return this.adminOathOtpTokenService.hasToken(userId);
   }

   @Override
   public boolean deleteToken(UserId userId) {
      return this.adminOathOtpTokenService.deleteToken(userId);
   }

   @Override
   public Optional<OathOtpToken> retrieveToken(UserId userId) {
      return this.adminOathOtpTokenService.retrieveToken(userId);
   }

   @Override
   public OathOtpToken createToken(UserId userId) throws ViolationException {
      return this.adminOathOtpTokenService.createToken(userId);
   }

   @SuppressFBWarnings(justification = "generated code")
   public static AdminTotpTokenServiceImpl.AdminTotpTokenServiceImplBuilder builder() {
      return new AdminTotpTokenServiceImpl.AdminTotpTokenServiceImplBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class AdminTotpTokenServiceImplBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private AdminOathOtpTokenServiceImpl adminOathOtpTokenService;

      @SuppressFBWarnings(justification = "generated code")
      AdminTotpTokenServiceImplBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public AdminTotpTokenServiceImpl.AdminTotpTokenServiceImplBuilder adminOathOtpTokenService(AdminOathOtpTokenServiceImpl adminOathOtpTokenService) {
         this.adminOathOtpTokenService = adminOathOtpTokenService;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public AdminTotpTokenServiceImpl build() {
         return new AdminTotpTokenServiceImpl(this.adminOathOtpTokenService);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "AdminTotpTokenServiceImpl.AdminTotpTokenServiceImplBuilder(adminOathOtpTokenService=" + this.adminOathOtpTokenService + ")";
      }
   }
}
