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.ArtSchoolTagVo;
import org.dromara.art.domain.bo.ArtSchoolTagBo;
import org.dromara.art.service.IArtSchoolTagService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校标签
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolTag")
public class ArtSchoolTagController extends BaseController {

    private final IArtSchoolTagService artSchoolTagService;

    /**
     * 查询学校标签列表
     */
    @SaCheckPermission("art:schoolTag:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolTagVo> list(ArtSchoolTagBo bo, PageQuery pageQuery) {
        return artSchoolTagService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校标签列表
     */
    @SaCheckPermission("art:schoolTag:export")
    @Log(title = "学校标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolTagBo bo, HttpServletResponse response) {
        List<ArtSchoolTagVo> list = artSchoolTagService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校标签", ArtSchoolTagVo.class, response);
    }

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

    /**
     * 新增学校标签
     */
    @SaCheckPermission("art:schoolTag:add")
    @Log(title = "学校标签", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolTagBo bo) {
        return toAjax(artSchoolTagService.insertByBo(bo));
    }

    /**
     * 修改学校标签
     */
    @SaCheckPermission("art:schoolTag:edit")
    @Log(title = "学校标签", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolTagBo bo) {
        return toAjax(artSchoolTagService.updateByBo(bo));
    }

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