package com.red.circle.wallet.inner.endpoint.tmp;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.core.dto.ReqSysOrigin;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.wallet.app.dto.cmd.UserPayAuthCheckCmd;
import com.red.circle.wallet.app.dto.cmd.UserPayAuthCmd;
import com.red.circle.wallet.app.service.UserPayAuthService;
import com.red.circle.wallet.inner.endpoint.tmp.api.PayAuthClientRestApi;
import com.red.circle.wallet.inner.model.tmp.CommonRestApiCmd;
import com.red.circle.wallet.inner.model.tmp.UserPayAuthCheckRestApiCmd;
import com.red.circle.wallet.inner.model.tmp.UserPayAuthRestApiCmd;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author pengliang on 2024/1/5
 */
@Validated
@RestController
@RequestMapping(value = PayAuthClientRestApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class PayAuthClientRestEndpoint implements PayAuthClientRestApi {

  private final UserPayAuthService userPayAuthService;

  @Override
  public ResultResponse<Void> addOrUpdatePayPwd(UserPayAuthRestApiCmd cmd) {
    UserPayAuthCmd newCmd = new UserPayAuthCmd();
    newCmd.setReqSysOrigin(ReqSysOrigin.of(cmd.getSysOrigin()));
    newCmd.setReqUserId(cmd.getReqUserId());
    newCmd.setPwd(cmd.getPwd());
    newCmd.setStatus(cmd.getStatus());
    newCmd.setOriginalPwd(cmd.getOriginalPwd());
    userPayAuthService.addOrUpdatePayPwd(newCmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Boolean> isPwdSetup(CommonRestApiCmd cmd) {
    AppExtCommand newCmd = new AppExtCommand();
    newCmd.setReqSysOrigin(ReqSysOrigin.of(cmd.getSysOrigin()));
    newCmd.setReqUserId(cmd.getReqUserId());
    return ResultResponse.success(userPayAuthService.isPwdSetup(newCmd));
  }

  @Override
  public ResultResponse<Boolean> payCheckPwd(UserPayAuthCheckRestApiCmd cmd) {
    UserPayAuthCheckCmd newCmd = new UserPayAuthCheckCmd();
    newCmd.setReqSysOrigin(ReqSysOrigin.of(cmd.getSysOrigin()));
    newCmd.setReqUserId(cmd.getReqUserId());
    newCmd.setPwd(cmd.getPwd());
    return ResultResponse.success(userPayAuthService.payCheckPwd(newCmd));
  }
}
