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


import com.red.circle.console.app.service.app.sys.pay.SysPayFactoryService;
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.SysPayFactoryConfigCmd;
import com.red.circle.order.inner.model.cmd.SysPayFactoryCmd;
import com.red.circle.order.inner.model.cmd.SysPayFactoryQryCmd;
import com.red.circle.order.inner.model.dto.SysPayFactoryConfigDTO;
import com.red.circle.order.inner.model.dto.SysPayFactoryDTO;
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-factory", produces = MediaType.APPLICATION_JSON_VALUE)
public class SysPayFactoryController extends BaseController {

  private final SysPayFactoryService sysPayFactoryService;

  /**
   * 分页列表.
   */
  @GetMapping("/page")
  public PageResult<SysPayFactoryDTO> pageSysPayChannel(SysPayFactoryQryCmd query) {
    return sysPayFactoryService.pageSysPayChannel(query);
  }

  /**
   * 列表.
   */
  @GetMapping("/list")
  public List<SysPayFactoryDTO> listSysPayChannel() {
    return sysPayFactoryService.listSysPayChannel();
  }

  /**
   * 添加.
   */
  @OpsOperationReqLog("添加-支付厂商")
  @PostMapping("/add")
  public void addSysPayChannel(@RequestBody @Validated SysPayFactoryCmd param) {
    param.setCreateUser(param.getReqUserId());
    param.setCreateTime(TimestampUtils.now());
    sysPayFactoryService.addSysPayChannel(param);
  }

  /**
   * 修改.
   */
  @OpsOperationReqLog("修改-支付厂商")
  @PostMapping("/update")
  public void updateSysPayChannel(@RequestBody @Validated SysPayFactoryCmd param) {
    param.setUpdateUser(param.getReqUserId());
    param.setUpdateTime(TimestampUtils.now());
    sysPayFactoryService.updateSysPayChannel(param);
  }

  /**
   * 厂商运行配置.
   */
  @GetMapping("/config")
  public SysPayFactoryConfigDTO getFactoryConfig(SysPayFactoryConfigCmd param) {
    return sysPayFactoryService.getFactoryConfig(param);
  }

  /**
   * 保存厂商运行配置.
   */
  @OpsOperationReqLog("保存-支付厂商运行配置")
  @PostMapping("/config/save")
  public void saveOrUpdateFactoryConfig(@RequestBody @Validated SysPayFactoryConfigCmd param) {
    param.setUpdateUser(param.getReqUserId());
    param.setUpdateTime(TimestampUtils.now());
    sysPayFactoryService.saveOrUpdateFactoryConfig(param);
  }

}
