content: /*
   * Copyright 2018-2024 adorsys GmbH & Co KG
   *
   * This program is free software: you can redistribute it and/or modify it
   * under the terms of the GNU Affero General Public License as published
   * by the Free Software Foundation, either version 3 of the License, or (at
   * your option) any later version. This program is distributed in the hope that
   * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   * See the GNU Affero General Public License for more details.
   *
   * You should have received a copy of the GNU Affero General Public License
   * along with this program. If not, see https://www.gnu.org/licenses/.
   *
   * This project is also available under a separate commercial license. You can
   * contact us at sales@adorsys.com.
   */
  
  package de.adorsys.psd2.xs2a.web.mapper;
  
  import de.adorsys.psd2.model.ScaStatus;
  import de.adorsys.psd2.xs2a.core.sca.ChallengeData;
  import de.adorsys.psd2.xs2a.core.sca.OtpFormat;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
  import org.springframework.stereotype.Service;
  
  import java.util.Optional;
  
  
  @Service
  public class CoreObjectsMapper {
      @Nullable
      public ScaStatus mapToModelScaStatus(@NotNull de.adorsys.psd2.xs2a.core.sca.ScaStatus scaStatus) {
          return ScaStatus.fromValue(scaStatus.getValue());
      }
  
      @Nullable
      public de.adorsys.psd2.model.ChallengeData mapToChallengeData(ChallengeData challengeData) {
          return Optional.ofNullable(challengeData)
                     .map(cd -> new de.adorsys.psd2.model.ChallengeData()
                                    .image(cd.getImage())
                                    .data(cd.getData())
                                    .imageLink(cd.getImageLink())
                                    .otpMaxLength(cd.getOtpMaxLength())
                                    .otpFormat(mapToOtpFormat(cd.getOtpFormat()))
                                    .additionalInformation(cd.getAdditionalInformation())
                         ).orElse(null);
      }
  
      @Nullable
      private de.adorsys.psd2.model.ChallengeData.OtpFormatEnum mapToOtpFormat(OtpFormat otpFormat) {
          return Optional.ofNullable(otpFormat)
                     .map(OtpFormat::getValue)
                     .map(de.adorsys.psd2.model.ChallengeData.OtpFormatEnum::fromValue)
                 .orElse(null);
      }
  }
  