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


import com.red.circle.console.app.service.app.sys.pay.SysPayCountryService;
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.SysPayCountryAddCmd;
import com.red.circle.order.inner.model.cmd.SysPayCountryQryCmd;
import com.red.circle.order.inner.model.dto.PayCountryDTO;
import java.math.BigDecimal;
import java.util.HashSet;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 开放支付国家 前端控制器.
 *
 * @author pengliang
 * @since 2021-11-29
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/sys-pay-open-country", produces = MediaType.APPLICATION_JSON_VALUE)
public class SysPayOpenCountryController extends BaseController {

  private final SysPayCountryService sysPayCountryService;

  /**
   * 开放支付国家-分页列表.
   */
  @GetMapping("/page")
  public PageResult<PayCountryDTO> page(SysPayCountryQryCmd query) {
    return sysPayCountryService.pageOpenPayCountry(query);
  }

  /**
   * 开放支付国家-列表.
   */
  @GetMapping("/list")
  public List<PayCountryDTO> list() {
    return sysPayCountryService.listOpenPayCountry(new HashSet<>());
  }

  /**
   * 根据区域id查询开放支付国家-列表.
   */
  @GetMapping("/list/region")
  public List<PayCountryDTO> listPayCountryByRegionId(String regionId) {
    return sysPayCountryService.listPayCountryByRegionId(regionId);
  }

  /**
   * 添加国家.
   */
  @OpsOperationReqLog("添加国家")
  @PostMapping("/add-batch")
  public void add(@RequestBody @Validated List<SysPayCountryAddCmd> params) {
    sysPayCountryService.addOpenPayCountry(params);
  }

  /**
   * 添加国家.
   */
  @OpsOperationReqLog("添加国家")
  @PostMapping("/del-batch")
  public void del(@RequestBody @Validated List<Long> countryIds) {
    sysPayCountryService.delOpenPayCountry(countryIds);
  }

  /**
   * 修改国家汇率.
   */
  @OpsOperationReqLog("修改国家汇率")
  @PostMapping("/update-exchange-rate")
  public void updateCountryExchangeRate(@RequestParam Long id,
      @RequestParam BigDecimal rate) {
    sysPayCountryService.updateUsdExchangeRate(id, rate);
  }

  /**
   * 修改国家货币code.
   */
  @OpsOperationReqLog("修改国家货币code")
  @PostMapping("/update-currency")
  public void updateCountryCurrency(@RequestParam Long id,
      @RequestParam String currency) {
    sysPayCountryService.updateCountryCurrency(id, currency);
  }

  /**
   * 修改权重.
   */
  @OpsOperationReqLog("修改权重")
  @PostMapping("/update-sort")
  public void updateSort(@RequestParam Long id,
      @RequestParam Integer sort) {
    sysPayCountryService.updateSort(id, sort);
  }

  /**
   * 修改国家上下架.
   */
  @OpsOperationReqLog("修改国家上下架")
  @GetMapping("/shelf")
  public void shelf(@RequestParam Long id,
      @RequestParam Boolean shelf) {
    sysPayCountryService.shelf(id, shelf);
  }


}
