package com.ruoyi.zhushi.controller;

import com.ruoyi.common.annotation.Log;
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.common.enums.BusinessType;
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")
    @Log(title = "打卡设置新增或者修改", businessType = BusinessType.UPDATE)
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DkCheckInConfigDTO dkCheckInConfigDTO) {
        return toAjax(dkConfigService.addConfig(dkCheckInConfigDTO));
    }


    // 删除
    @DeleteMapping("/deleteConfig/{id}")
    @Log(title = "打卡设置", businessType = BusinessType.DELETE)
    public R<Integer> remove(@PathVariable Long id) {
        return R.ok(dkConfigService.deleteConfig(id));
    }

    // 修改
    @PutMapping("/updateConfig")
    @Log(title = "打卡设置", businessType = BusinessType.UPDATE)
    public R<Void> edit(@RequestBody DkCheckInConfigDTO bo) {
        return toAjax(dkConfigService.updateConfig(bo));
    }
}
