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


import com.red.circle.console.app.dto.clienobject.sys.SysGiftConfigCO;
import com.red.circle.console.app.dto.cmd.app.sys.GiftConsoleQryCmd;
import com.red.circle.console.app.service.app.sys.SysGiftConfigService;
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.other.inner.model.dto.material.GiftConfigDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统礼物配置 前端控制器.
 * </p>
 *
 * @author houyong
 * @since 2021-01-12
 */
@RestController
@RequestMapping("/sys/gift/config")
@RequiredArgsConstructor
public class SysGiftConfigRestController extends BaseController {

  private final SysGiftConfigService sysGiftConfigService;

  /**
   * 获取指定平台礼物信息.
   */
  @GetMapping("/sys-origin/{sysOrigin}")
  public List<SysGiftConfigCO> listBySysOrigin(
      @PathVariable("sysOrigin") String sysOrigin) {
    return sysGiftConfigService.listBySysOrigin(sysOrigin);
  }

  /**
   * 获取礼物信息.
   */
  @GetMapping
  public PageResult<SysGiftConfigCO> pageGiftInfo(GiftConsoleQryCmd query) {
    return sysGiftConfigService.pageGiftInfo(query);
  }

  @OpsOperationReqLog(value = "修改礼物信息")
  @PutMapping
  public void updateGift(@RequestBody SysGiftConfigCO param) {
    param.setUpdateUser(getReqUserId());
    sysGiftConfigService.updateGift(param);
  }

  @OpsOperationReqLog(value = "新增礼物信息")
  @PostMapping
  public void addGift(@RequestBody SysGiftConfigCO param) {
    param.setCreateUser(getReqUserId());
    param.setDel(Boolean.TRUE);
    sysGiftConfigService.addGift(param);
  }

  /**
   * 上下架礼物.
   */
  @GetMapping("/switch/{id}/{status}")
  public void deleteGift(@PathVariable("id") Long id,
      @PathVariable("status") Boolean status) {
    sysGiftConfigService.switchDelStatus(id, status);
  }

  /**
   * 礼物列表.
   */
  @GetMapping("/listByTab/{sysOrigin}/{giftTab}")
  public List<GiftConfigDTO> listByTab(@PathVariable("sysOrigin") String sysOrigin,
      @PathVariable("giftTab") String giftTab) {
    return sysGiftConfigService.listByTab(sysOrigin, giftTab);
  }

  /**
   * 获取赠送Cp组合礼物ID.
   */
  @GetMapping("/pair/cp/give/gift/{sysOrigin}")
  public String getPairCpGiveGiftId(@PathVariable("sysOrigin") String sysOrigin) {
    return sysGiftConfigService.getPairCpGiveGiftId(sysOrigin);
  }

  /**
   * 保存赠送Cp组合礼物ID.
   */
  @GetMapping("/pair/cp/give/gift/{giftId}/{sysOrigin}")
  public void pushPairCpGiveGiftId(@PathVariable("giftId") Long giftId,
      @PathVariable("sysOrigin") String sysOrigin) {
    sysGiftConfigService.pushPairCpGiveGiftId(giftId, sysOrigin);
  }

  /**
   * 礼物列表.
   */
  @GetMapping("/listByTab")
  public List<GiftConfigDTO> listByTabV2(GiftConsoleQryCmd query) {
    return sysGiftConfigService.listByTabV2(query);
  }

}
