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.ArtSchoolMajorTagVo;
import org.dromara.art.domain.bo.ArtSchoolMajorTagBo;
import org.dromara.art.service.IArtSchoolMajorTagService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 专业标签
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolMajorTag")
public class ArtSchoolMajorTagController extends BaseController {

    private final IArtSchoolMajorTagService artSchoolMajorTagService;

    /**
     * 查询专业标签列表
     */
    @SaCheckPermission("art:schoolMajorTag:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolMajorTagVo> list(ArtSchoolMajorTagBo bo, PageQuery pageQuery) {
        return artSchoolMajorTagService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出专业标签列表
     */
    @SaCheckPermission("art:schoolMajorTag:export")
    @Log(title = "专业标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolMajorTagBo bo, HttpServletResponse response) {
        List<ArtSchoolMajorTagVo> list = artSchoolMajorTagService.queryList(bo);
        ExcelUtil.exportExcel(list, "专业标签", ArtSchoolMajorTagVo.class, response);
    }

    /**
     * 获取专业标签详细信息
     *
     * @param majorTagId 主键
     */
    @SaCheckPermission("art:schoolMajorTag:query")
    @GetMapping("/{majorTagId}")
    public R<ArtSchoolMajorTagVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long majorTagId) {
        return R.ok(artSchoolMajorTagService.queryById(majorTagId));
    }

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

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

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