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.ArtSchoolNameVo;
import org.dromara.art.domain.bo.ArtSchoolNameBo;
import org.dromara.art.service.IArtSchoolNameService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校多名称
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolName")
public class ArtSchoolNameController extends BaseController {

    private final IArtSchoolNameService artSchoolNameService;

    /**
     * 查询学校多名称列表
     */
    @SaCheckPermission("art:schoolName:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolNameVo> list(ArtSchoolNameBo bo, PageQuery pageQuery) {
        return artSchoolNameService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校多名称列表
     */
    @SaCheckPermission("art:schoolName:export")
    @Log(title = "学校多名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolNameBo bo, HttpServletResponse response) {
        List<ArtSchoolNameVo> list = artSchoolNameService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校多名称", ArtSchoolNameVo.class, response);
    }

    /**
     * 获取学校多名称详细信息
     *
     * @param schoolNameId 主键
     */
    @SaCheckPermission("art:schoolName:query")
    @GetMapping("/{schoolNameId}")
    public R<ArtSchoolNameVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long schoolNameId) {
        return R.ok(artSchoolNameService.queryById(schoolNameId));
    }

    /**
     * 新增学校多名称
     */
    @SaCheckPermission("art:schoolName:add")
    @Log(title = "学校多名称", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolNameBo bo) {
        return toAjax(artSchoolNameService.insertByBo(bo));
    }

    /**
     * 修改学校多名称
     */
    @SaCheckPermission("art:schoolName:edit")
    @Log(title = "学校多名称", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolNameBo bo) {
        return toAjax(artSchoolNameService.updateByBo(bo));
    }

    /**
     * 删除学校多名称
     *
     * @param schoolNameIds 主键串
     */
    @SaCheckPermission("art:schoolName:remove")
    @Log(title = "学校多名称", businessType = BusinessType.DELETE)
    @DeleteMapping("/{schoolNameIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] schoolNameIds) {
        return toAjax(artSchoolNameService.deleteWithValidByIds(List.of(schoolNameIds), true));
    }
}
