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

import com.red.circle.console.app.service.app.sys.CpCabinConfigService;
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.cmd.sys.SysCpCabinConfigQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysCpCabinConfigDTO;
import com.red.circle.tool.core.date.TimestampUtils;
import lombok.AllArgsConstructor;
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>
 * CP小屋配置 前端控制器.
 * </p>
 *
 * @author zongpubin on 2023-11-13
 */
@AllArgsConstructor
@RestController
@RequestMapping("/sys/cp-cabin/config")
public class SysCpCabinConfigRestController extends BaseController {

  private final CpCabinConfigService cpCabinConfigService;

  /**
   * 获取小屋配置信息.
   */
  @GetMapping
  public PageResult<SysCpCabinConfigDTO> getCpCabin(SysCpCabinConfigQryCmd query) {
    return cpCabinConfigService.getCpCabin(query);
  }

  @OpsOperationReqLog("添加小屋配置")
  @PostMapping
  public void addCpCabin(@RequestBody SysCpCabinConfigDTO dto) {
    cpCabinConfigService.addCpCabin(dto);
  }

  @OpsOperationReqLog("删除小屋配置")
  @DeleteMapping("/{id}")
  public void deleteCpCabin(@PathVariable("id") Long id) {
    cpCabinConfigService.removeCpCabin(id);
  }

  @OpsOperationReqLog("修改小屋配置")
  @PutMapping
  public void updateCpCabin(@RequestBody SysCpCabinConfigDTO dto) {
    dto.setUpdateUser(getReqUserId());
    dto.setUpdateTime(TimestampUtils.now());
    cpCabinConfigService.updateCpCabin(dto);
  }

}
