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


import com.red.circle.console.app.service.app.sys.SysBadgeConfigService;
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.enums.sys.SysBadgeConfigTypeEnum;
import com.red.circle.other.inner.model.cmd.sys.GiveBadgeConfigQryCmd;
import com.red.circle.other.inner.model.cmd.sys.SysBadgeConfigQryCmd;
import com.red.circle.other.inner.model.dto.material.BadgeConfigDTO;
import com.red.circle.other.inner.model.dto.material.BadgePictureConfigDTO;
import com.red.circle.other.inner.model.dto.sys.GiveBadgeConfigDTO;
import com.red.circle.other.inner.model.dto.sys.SelectBadgeDTO;
import com.red.circle.other.inner.model.dto.sys.SysBadgeConfigInfoDTO;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 徽章配置 前端控制器.
 *
 * @author houyong
 * @since 2021-03-19
 */
@RestController
@RequestMapping("/sys/badge/config")
@RequiredArgsConstructor
public class SysBadgeConfigRestController extends BaseController {

  private final SysBadgeConfigService sysBadgeConfigService;

  /**
   * 获取徽章规则信息.
   */
  @GetMapping
  public PageResult<SysBadgeConfigInfoDTO> getBadgeConfig(SysBadgeConfigQryCmd query) {
    return sysBadgeConfigService.getBadgeConfig(query);
  }

  @OpsOperationReqLog(value = "修改徽章信息")
  @PutMapping
  public void updateBadgeConfig(@RequestBody BadgeConfigDTO badgeConfigDTO) {
    badgeConfigDTO.setUpdateUser(getReqUserId());
    sysBadgeConfigService.updateBadgeConfig(badgeConfigDTO);
  }

  /**
   * 新增徽章信息.
   */
  @OpsOperationReqLog(value = "新增徽章信息")
  @PostMapping
  public void addBadgeConfig(@RequestBody BadgeConfigDTO badgeConfigDTO) {
    badgeConfigDTO.setCreateUser(getReqUserId());
    sysBadgeConfigService.addBadgeConfig(badgeConfigDTO);
  }

  /**
   * 删除徽章.
   */
  @GetMapping("/delete/{id}")
  public void deleteBadge(@PathVariable("id") Long id) {
    sysBadgeConfigService.deleteBadge(id);
  }

  /**
   * 获取徽章信息分页-赠送非成就徽章.
   */
  @GetMapping("/getGiveBadgePage")
  public PageResult<GiveBadgeConfigDTO> getGiveBadgePage(GiveBadgeConfigQryCmd query) {
    return sysBadgeConfigService.getGiveBadgePage(query);
  }

  /**
   * 赠送徽章.
   */
  @GetMapping("/give/badge/{badgeId}/{userId}")
  public void giveBadge(@PathVariable("badgeId") Long badgeId,
      @PathVariable("userId") Long userId) {
    sysBadgeConfigService.giveBadge(badgeId, userId);
  }

  /**
   * 收回徽章.
   */
  @GetMapping("/retrieve/badge/{badgeId}/{userId}")
  public void retrieveBadge(@PathVariable("badgeId") Long badgeId,
      @PathVariable("userId") Long userId) {
    sysBadgeConfigService.retrieveBadge(badgeId, userId);
  }

  /**
   * 获得活动徽章集合.
   */
  @GetMapping("/list/badge-by-type")
  public List<SelectBadgeDTO> listBadgeByType(
      @RequestParam SysBadgeConfigTypeEnum type) {
    return sysBadgeConfigService.listBadgeByType(type);
  }

  /**
   * 获取平台徽章.
   */
  @PostMapping("/sys-origin")
  public List<BadgePictureConfigDTO> listBySysOrigin(@RequestParam String sysOrigin,
      @RequestParam SysBadgeConfigTypeEnum type) {
    return sysBadgeConfigService.listBadgePictureBySysOrigin(sysOrigin, type);
  }

}
