package com.red.circle.console.adapter.app.sys.pay;


import com.red.circle.console.app.service.app.sys.pay.SysPayChannelService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.order.inner.model.cmd.SysPayChannelCmd;
import com.red.circle.order.inner.model.cmd.SysPayChannelQryCmd;
import com.red.circle.order.inner.model.dto.SysPayChannelDTO;
import com.red.circle.tool.core.date.TimestampUtils;
import java.util.List;
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 pengliang
 * @since 2021-11-29
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/sys-pay-channel", produces = MediaType.APPLICATION_JSON_VALUE)
public class SysPayChannelController extends BaseController {

  private final SysPayChannelService sysPayChannelService;

  /**
   * 渠道分页列表.
   */
  @GetMapping("/page")
  public PageResult<SysPayChannelDTO> pageChannel(SysPayChannelQryCmd query) {
    return sysPayChannelService.pageChannel(query);
  }

  /**
   * 列表.
   */
  @GetMapping("/list")
  public List<SysPayChannelDTO> listChannel() {
    return sysPayChannelService.listChannel();
  }

  /**
   * 添加.
   */
  @OpsOperationReqLog("添加-支付渠道")
  @PostMapping("/add")
  public void addChannel(@RequestBody @Validated SysPayChannelCmd param) {
    param.setCreateUser(param.getReqUserId());
    param.setCreateTime(TimestampUtils.now());
    sysPayChannelService.addChannel(param);
  }

  /**
   * 修改.
   */
  @OpsOperationReqLog("修改-支付渠道")
  @PostMapping("/update")
  public void updateChannel(@RequestBody @Validated SysPayChannelCmd param) {
    param.setUpdateUser(param.getReqUserId());
    param.setUpdateTime(TimestampUtils.now());
    sysPayChannelService.updateChannel(param);
  }

}
