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.clientobject.BeanToGoldCO;
import com.red.circle.wallet.app.service.WalletBeanService;
import com.red.circle.wallet.inner.endpoint.tmp.api.BeanClientRestApi;
import com.red.circle.wallet.inner.model.tmp.BeanToGoldTmpCO;
import com.red.circle.wallet.inner.model.tmp.CommonRestApiCmd;
import java.util.Objects;
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 = BeanClientRestApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class BeanClientRestEndpoint implements BeanClientRestApi {

  private final WalletBeanService walletBeanService;

  @Override
  public ResultResponse<BeanToGoldTmpCO> getExchange(CommonRestApiCmd cmd) {
    AppExtCommand newCmd = new AppExtCommand();
    newCmd.setReqUserId(cmd.getReqUserId());
    newCmd.setReqSysOrigin(ReqSysOrigin.of(cmd.getSysOrigin()));
    BeanToGoldCO co = walletBeanService.getExchange(newCmd);

    if (Objects.isNull(co)) {
      return ResultResponse.success();
    }
    BeanToGoldTmpCO tmpCo = new BeanToGoldTmpCO();
    tmpCo.setBeanBalance(co.getBeanBalance());
    tmpCo.setObtainGold(co.getObtainGold());
    tmpCo.setRate(co.getRate());
    return ResultResponse.success(tmpCo);
  }

}
