package com.red.circle.console.app.service.app.user;

import com.red.circle.auth.inner.endpoint.AuthClient;
import com.red.circle.console.app.dto.clienobject.user.UserAuthDetailsCO;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.security.UserCredential;
import com.red.circle.wallet.inner.endpoint.user.PayAuthClient;
import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO;
import com.red.circle.other.inner.model.dto.user.account.UserMobileUpdateCmd;
import com.red.circle.other.inner.endpoint.user.user.AppUserAccountClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户活动月度领取记录
 * </p>
 *
 * @author pengshigang
 * @since 2021-06-19
 */
@Service
@RequiredArgsConstructor
public class UserAuthTypeServiceImpl implements
    UserAuthTypeService {

  private final AuthClient authClient;
  private final PayAuthClient payAuthClient;
  private final AppUserAccountClient userAccountClient;

  /**
   * 获取注册信息.
   */
  @Override
  public UserAuthTypeDTO updateUserInfo(Long userId) {
    return ResponseAssert.requiredSuccess(userAccountClient.getByUserIdOne(userId));
  }

  /**
   * 用户登录令牌.
   */
  @Override
  public UserCredential token(Long userId) {
    return ResponseAssert.requiredSuccess(authClient.getUserCredential(userId));
  }

  @Override
  public void tokenDel(Long userId) {
    ResponseAssert.requiredSuccess(authClient.removeToken(userId));
  }

  /**
   * 获得认证详情.
   */
  @Override
  public UserAuthDetailsCO getUserAuthDetails(Long userId) {
    return new UserAuthDetailsCO()
        .setAuths(ResponseAssert.requiredSuccess(userAccountClient.listByUserId(userId)))
        .setUserId(userId)
        .setUserMobileAuth(
            ResponseAssert.requiredSuccess(userAccountClient.getMobileAuthByUserId(userId)));
  }

  /**
   * 修改绑定手机认证信息.
   */
  @Override
  public void editUserMobileAuth(UserMobileUpdateCmd param) {
    ResponseAssert.requiredSuccess(userAccountClient.editUserMobileAuth(param));
  }

  /**
   * 删除绑定手机认证信息.
   */
  @Override
  public void deleteUserMobileAuth(Long userId) {
    ResponseAssert.requiredSuccess(userAccountClient.deleteUserMobileAuth(userId));
  }

  /**
   * 重置用户账号密码登录信息.
   */
  @Override
  public void initUserAccountLogin(Long userId) {
    ResponseAssert.requiredSuccess(userAccountClient.deleteAccountAuthCacheByUserId(userId));
  }

  /**
   * 删除用户账号密码登录信息.
   */
  @Override
  public void deleteUserAccountLogin(Long userId) {
    ResponseAssert.requiredSuccess(userAccountClient.deleteUserAccountLogin(userId));
  }

  @Override
  public void initUserPayAuth(Long userId) {
    payAuthClient.initUserPayAuth(userId);
  }

  @Override
  public void deleteUserPayAuth(Long userId) {
    payAuthClient.deleteUserPayAuth(userId);
  }
}
