package org.dromara.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.domain.vo.SenEventsObjectVo;
import org.dromara.domain.bo.SenEventsObjectBo;
import org.dromara.service.ISenEventsObjectService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 事件对象
 *
 * @author luogang
 * @date 2024-09-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dromara/eventsObject")
public class SenEventsObjectController extends BaseController {

    private final ISenEventsObjectService senEventsObjectService;

    /**
     * 查询事件对象列表
     */
    @SaCheckPermission("dromara:eventsObject:list")
    @GetMapping("/list")
    public TableDataInfo<SenEventsObjectVo> list(SenEventsObjectBo bo, PageQuery pageQuery) {
        return senEventsObjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出事件对象列表
     */
    @SaCheckPermission("dromara:eventsObject:export")
    @Log(title = "事件对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SenEventsObjectBo bo, HttpServletResponse response) {
        List<SenEventsObjectVo> list = senEventsObjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "事件对象", SenEventsObjectVo.class, response);
    }

    /**
     * 获取事件对象详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("dromara:eventsObject:query")
    @GetMapping("/{id}")
    public R<SenEventsObjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(senEventsObjectService.queryById(id));
    }

    /**
     * 新增事件对象
     */
    @SaCheckPermission("dromara:eventsObject:add")
    @Log(title = "事件对象", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SenEventsObjectBo bo) {
        return toAjax(senEventsObjectService.insertByBo(bo));
    }

    /**
     * 修改事件对象
     */
    @SaCheckPermission("dromara:eventsObject:edit")
    @Log(title = "事件对象", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SenEventsObjectBo bo) {
        return toAjax(senEventsObjectService.updateByBo(bo));
    }

    /**
     * 删除事件对象
     *
     * @param ids 主键串
     */
    @SaCheckPermission("dromara:eventsObject:remove")
    @Log(title = "事件对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(senEventsObjectService.deleteWithValidByIds(List.of(ids), true));
    }
}
