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


import com.red.circle.console.app.service.app.sys.SysEnumConfigService;
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.config.EnumConfigKey;
import com.red.circle.other.inner.model.cmd.sys.SysEnumConfigQryCmd;
import com.red.circle.other.inner.model.dto.sys.EnumConfigDTO;
import com.red.circle.other.inner.model.dto.sys.SysEnumConfigSortDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
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 pengliang
 * @since 2019-11-08
 */
@RestController
@RequestMapping(value = "/sys/enum/config")
@RequiredArgsConstructor
public class SysEnumConfigRestController extends BaseController {

  private final SysEnumConfigService sysEnumConfigService;

  /**
   * 获取系统枚举常量分页列表.
   */
  @GetMapping(value = "/page")
  public PageResult<EnumConfigDTO> pageSysEnumConfig(SysEnumConfigQryCmd query) {
    return sysEnumConfigService.pageSysEnumConfig(query);
  }

  /**
   * 获取系统枚举常量list列表.
   */
  @GetMapping(value = "/list/{groupName}")
  public List<EnumConfigDTO> sysEnumConfigList(
      @PathVariable("groupName") String groupName) {
    return sysEnumConfigService.sysEnumConfigList(groupName);
  }

  /**
   * 获取违规头像.
   */
  @GetMapping("/violation/avatar")
  public String getViolationAvatar() {
    return sysEnumConfigService.getViolationAvatar(EnumConfigKey.VIOLATION_PICTURE);
  }

  /**
   * 添加系统枚举常量.
   */
  @OpsOperationReqLog(value = "添加系统枚举常量")
  @PostMapping
  public void saveSysEnumConfig(@RequestBody EnumConfigDTO sysEnumConfig) {
    sysEnumConfig.setCreateUser(getReqUserId());
    sysEnumConfigService.saveSysEnumConfig(sysEnumConfig);
  }

  @OpsOperationReqLog(value = "修改系统枚举常量")
  @PutMapping
  public void updateSysEnumConfig(@RequestBody EnumConfigDTO sysEnumConfig) {
    sysEnumConfig.setUpdateUser(getReqUserId());
    sysEnumConfigService.updateSysEnumConfig(sysEnumConfig);
  }

  @OpsOperationReqLog(value = "删除系统厂里枚举")
  @DeleteMapping("/{id}")
  public void deleteSysEnumConfig(@PathVariable("id") Long id) {
    sysEnumConfigService.deleteBySysOriginAndName(id);
  }

  @OpsOperationReqLog(value = "调整序号")
  @PostMapping("/sort")
  public void updateSort(
      @RequestBody List<SysEnumConfigSortDTO> sysEnumConfigSortParams) {
    sysEnumConfigService.updateSort(sysEnumConfigSortParams);
  }

}
