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

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.wallet.inner.endpoint.salary.api.UserSalaryAccountClientApi;
import com.red.circle.wallet.inner.model.cmd.SalaryIssueInnerCmd;
import com.red.circle.wallet.inner.model.cmd.SalaryRunningWaterQueryInnerCmd;
import com.red.circle.wallet.inner.model.cmd.SalaryWithdrawInnerCmd;
import com.red.circle.wallet.inner.model.dto.SalaryAccountBalanceDTO;
import com.red.circle.wallet.inner.model.dto.SalaryIssueResultDTO;
import com.red.circle.wallet.inner.model.dto.SalaryRunningWaterDTO;
import com.red.circle.wallet.inner.service.salary.UserSalaryAccountClientService;
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;

import java.math.BigDecimal;

/**
 * 工资账户 Client Endpoint.
 */
@Validated
@RestController
@RequestMapping(value = UserSalaryAccountClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class UserSalaryAccountClientEndpoint implements UserSalaryAccountClientApi {

  private final UserSalaryAccountClientService userSalaryAccountClientService;

  @Override
  public ResultResponse<SalaryAccountBalanceDTO> getBalance(Long userId, String salaryType) {
    return ResultResponse.success(userSalaryAccountClientService.getBalance(userId, salaryType));
  }

  @Override
  public ResultResponse<SalaryIssueResultDTO> issueSalary(SalaryIssueInnerCmd cmd) {
    return ResultResponse.success(userSalaryAccountClientService.issueSalary(cmd));
  }

  @Override
  public ResultResponse<Void> withdrawRefund(SalaryWithdrawInnerCmd cmd) {
    userSalaryAccountClientService.withdrawRefund(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PageResult<SalaryRunningWaterDTO>> queryRunningWater(
      SalaryRunningWaterQueryInnerCmd cmd) {
    return ResultResponse.success(userSalaryAccountClientService.queryRunningWater(cmd));
  }

  @Override
  public ResultResponse<BigDecimal> getTotalIncome(Long userId, String salaryType) {
    return ResultResponse.success(userSalaryAccountClientService.getTotalIncome(userId, salaryType));
  }
}
