package org.dromara.art.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.art.domain.vo.ArtSchoolDormVo;
import org.dromara.art.domain.bo.ArtSchoolDormBo;
import org.dromara.art.service.IArtSchoolDormService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 校区宿舍条件
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolDorm")
public class ArtSchoolDormController extends BaseController {

    private final IArtSchoolDormService artSchoolDormService;

    /**
     * 查询校区宿舍条件列表
     */
    @SaCheckPermission("art:schoolDorm:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolDormVo> list(ArtSchoolDormBo bo, PageQuery pageQuery) {
        return artSchoolDormService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出校区宿舍条件列表
     */
    @SaCheckPermission("art:schoolDorm:export")
    @Log(title = "校区宿舍条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolDormBo bo, HttpServletResponse response) {
        List<ArtSchoolDormVo> list = artSchoolDormService.queryList(bo);
        ExcelUtil.exportExcel(list, "校区宿舍条件", ArtSchoolDormVo.class, response);
    }

    /**
     * 获取校区宿舍条件详细信息
     *
     * @param dormId 主键
     */
    @SaCheckPermission("art:schoolDorm:query")
    @GetMapping("/{dormId}")
    public R<ArtSchoolDormVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long dormId) {
        return R.ok(artSchoolDormService.queryById(dormId));
    }

    /**
     * 新增校区宿舍条件
     */
    @SaCheckPermission("art:schoolDorm:add")
    @Log(title = "校区宿舍条件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolDormBo bo) {
        return toAjax(artSchoolDormService.insertByBo(bo));
    }

    /**
     * 修改校区宿舍条件
     */
    @SaCheckPermission("art:schoolDorm:edit")
    @Log(title = "校区宿舍条件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolDormBo bo) {
        return toAjax(artSchoolDormService.updateByBo(bo));
    }

    /**
     * 删除校区宿舍条件
     *
     * @param dormIds 主键串
     */
    @SaCheckPermission("art:schoolDorm:remove")
    @Log(title = "校区宿舍条件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dormIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] dormIds) {
        return toAjax(artSchoolDormService.deleteWithValidByIds(List.of(dormIds), true));
    }
}
