package com.red.circle.other.app.command.sys;


import com.red.circle.other.app.convertor.sys.OauthAccessTokenAppConvertor;
import com.red.circle.other.app.dto.clientobject.sys.OauthAccessTokenCO;
import com.red.circle.other.app.dto.cmd.sys.OauthCertificateCmd;
import com.red.circle.other.infra.database.cache.service.other.OauthCacheService;
import com.red.circle.other.infra.database.cache.token.OauthAccessTokenCertificate;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author pengliang on 2022/5/10
 */
@Component
@RequiredArgsConstructor
public class OauthResetIfAbsentCmdExe {

  private final OauthCacheService oauthCacheService;

  private OauthAccessTokenAppConvertor oauthAccessTokenAppConvertor;

  public OauthAccessTokenCO execute(OauthCertificateCmd cmd) {

    return Optional.ofNullable(
        oauthAccessTokenAppConvertor.toOauthAccessTokenCo(oauthCacheService.getUserIdByToken(
            OauthAccessTokenCertificate.getTokenKey(cmd.getSecretId())))).orElse(null);
  }

}
