package com.ruoyi.zhushi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.zhushi.entity.DkCheckInConfigDTO;
import com.ruoyi.zhushi.service.DkConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打卡配置控制台
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dk/config")
@Slf4j
public class DkConfigController extends BaseController {


    @Autowired
    private DkConfigService dkConfigService;


    // 主页面查询
    @GetMapping("/list")
    public List<DkCheckInConfigDTO> list(DkCheckInConfigDTO dkCheckInConfigDTO, PageQuery pageQuery) {
        return dkConfigService.queryList(dkCheckInConfigDTO);
    }

    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DkCheckInConfigDTO dkCheckInConfigDTO) {
        return toAjax(dkConfigService.addConfig(dkCheckInConfigDTO));
    }


    @DeleteMapping("/deleteConfig/{id}")
    public R<Integer> remove(@PathVariable Long id) {
        return R.ok(dkConfigService.deleteConfig(id));
    }

    @PutMapping("/updateConfig")
    public R<Void> edit(@RequestBody DkCheckInConfigDTO bo) {
        return toAjax(dkConfigService.updateConfig(bo));
    }
}
