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

import com.red.circle.console.app.dto.clienobject.user.UserSalaryDiamondBalanceCO;
import com.red.circle.console.app.dto.clienobject.user.UserSalaryDiamondRunningWaterCO;
import com.red.circle.console.app.service.app.user.UserSalaryDiamondService;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondBalanceQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondCmd;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondRunningWaterQryCmd;
import com.red.circle.wallet.inner.model.cmd.UserSalaryDiamondTransferCmd;
import com.red.circle.wallet.inner.model.enums.UserSalaryDiamondWaterEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户工资钻石
 *
 * @author zongpubin on 2024/3/13
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/user-salary-diamond", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserSalaryDiamondRestController extends BaseController {

  private final UserSalaryDiamondService userSalaryDiamondService;

  /**
   * 用户工资钻石列表.
   */
  @GetMapping("/page")
  public PageResult<UserSalaryDiamondBalanceCO> page(UserSalaryDiamondBalanceQryCmd query) {
    return userSalaryDiamondService.listUserSalaryDiamondBalance(query);
  }

  /**
   * 创建用户工资钻石账户.
   */
  @PostMapping("/create")
  public void createSalaryDiamondBalance(@RequestBody @Validated UserSalaryDiamondCmd param) {
    param.setOperationUserId(param.getReqUserId());
    param.setEvent(UserSalaryDiamondWaterEvent.CREATE_ACCOUNT);
    userSalaryDiamondService.createSalaryDiamondBalance(param);

  }

  /**
   * 发送用户工资钻石.
   */
  @PostMapping("/send")
  public void sendSalaryDiamond(@RequestBody @Validated UserSalaryDiamondCmd param) {
    param.setOperationUserId(param.getReqUserId());
    param.setEvent(UserSalaryDiamondWaterEvent.SYSTEM_COMPENSATE);
    userSalaryDiamondService.sendSalaryDiamond(param);

  }

  /**
   * 扣除用户工资钻石.
   */
  @PostMapping("/deduct")
  public void deductSalaryDiamond(@RequestBody @Validated UserSalaryDiamondCmd param) {
    param.setOperationUserId(param.getReqUserId());
    param.setEvent(UserSalaryDiamondWaterEvent.SYSTEM_DEDUCT);
    userSalaryDiamondService.deductSalaryDiamond(param);

  }

  /**
   * 用户工资钻石转账.
   */
  @PostMapping("/transfer")
  public void transferSalaryDiamond(@RequestBody @Validated UserSalaryDiamondTransferCmd param) {
    param.setOperationUserId(param.getReqUserId());
    userSalaryDiamondService.transferSalaryDiamond(param);

  }

  /**
   * 用户工资钻石流水.
   */
  @GetMapping("/running-water-page")
  public PageResult<UserSalaryDiamondRunningWaterCO> runningWaterPage(
      UserSalaryDiamondRunningWaterQryCmd query) {
    return userSalaryDiamondService.runningWaterPage(query);
  }

}
