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.ArtSchoolDetailVo;
import org.dromara.art.domain.bo.ArtSchoolDetailBo;
import org.dromara.art.service.IArtSchoolDetailService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校详细信息
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolDetail")
public class ArtSchoolDetailController extends BaseController {

    private final IArtSchoolDetailService artSchoolDetailService;

    /**
     * 查询学校详细信息列表
     */
    @SaCheckPermission("art:schoolDetail:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolDetailVo> list(ArtSchoolDetailBo bo, PageQuery pageQuery) {
        return artSchoolDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校详细信息列表
     */
    @SaCheckPermission("art:schoolDetail:export")
    @Log(title = "学校详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolDetailBo bo, HttpServletResponse response) {
        List<ArtSchoolDetailVo> list = artSchoolDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校详细信息", ArtSchoolDetailVo.class, response);
    }

    /**
     * 获取学校详细信息详细信息
     *
     * @param detailId 主键
     */
    @SaCheckPermission("art:schoolDetail:query")
    @GetMapping("/{detailId}")
    public R<ArtSchoolDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long detailId) {
        return R.ok(artSchoolDetailService.queryById(detailId));
    }

    /**
     * 新增学校详细信息
     */
    @SaCheckPermission("art:schoolDetail:add")
    @Log(title = "学校详细信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolDetailBo bo) {
        return toAjax(artSchoolDetailService.insertByBo(bo));
    }

    /**
     * 修改学校详细信息
     */
    @SaCheckPermission("art:schoolDetail:edit")
    @Log(title = "学校详细信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolDetailBo bo) {
        return toAjax(artSchoolDetailService.updateByBo(bo));
    }

    /**
     * 删除学校详细信息
     *
     * @param detailIds 主键串
     */
    @SaCheckPermission("art:schoolDetail:remove")
    @Log(title = "学校详细信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] detailIds) {
        return toAjax(artSchoolDetailService.deleteWithValidByIds(List.of(detailIds), true));
    }
}
