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

import com.red.circle.common.business.dto.cmd.IdStringCmd;
import com.red.circle.console.app.service.app.sys.SysRegionAssistConfigBackService;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.tool.core.date.TimestampUtils;
import com.red.circle.other.inner.model.cmd.user.RegionAssistConfigQryCmd;
import com.red.circle.other.inner.model.cmd.user.SysRegionAssistCmd;
import com.red.circle.other.inner.model.dto.user.reigon.SysRegionAssistConfigDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
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.RestController;

/**
 * 区域辅助数据.
 *
 * @author pengshigang on 2023/03/14
 */
@RestController
@RequestMapping("/region/assist/config")
@RequiredArgsConstructor
public class SysRegionAssistConfigResetController extends BaseController {

  private final SysRegionAssistConfigBackService sysRegionAssistConfigBackService;

  /**
   * 列表查询.
   */
  @GetMapping("/list")
  public List<SysRegionAssistConfigDTO> listByCondition(
      RegionAssistConfigQryCmd query) {
    return sysRegionAssistConfigBackService.listByCondition(query);
  }

  /**
   * 修改辅助数据.
   */
  @PostMapping("/update")
  public void update(@RequestBody @Validated SysRegionAssistCmd param) {
    param.setUpdateUser(param.getReqUserId());
    param.setUpdateTime(TimestampUtils.now());
    sysRegionAssistConfigBackService.update(param);
  }

  /**
   * 添加辅助数据.
   */
  @PostMapping("/add")
  public void add(@RequestBody @Validated SysRegionAssistCmd param) {
    param.setCreateUser(param.getReqUserId());
    param.setCreateTime(TimestampUtils.now());
    sysRegionAssistConfigBackService.add(param);
  }

  /**
   * 根据id删除辅助数据.
   */
  @GetMapping("/delete/{id}")
  public void deleteById(IdStringCmd cmd) {
    sysRegionAssistConfigBackService.deleteById(cmd.getId(), cmd.getReqUserId());
  }
}
