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.ArtSchoolMajorVo;
import org.dromara.art.domain.bo.ArtSchoolMajorBo;
import org.dromara.art.service.IArtSchoolMajorService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校专业
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolMajor")
public class ArtSchoolMajorController extends BaseController {

    private final IArtSchoolMajorService artSchoolMajorService;

    /**
     * 查询学校专业列表
     */
    @SaCheckPermission("art:schoolMajor:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolMajorVo> list(ArtSchoolMajorBo bo, PageQuery pageQuery) {
        return artSchoolMajorService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校专业列表
     */
    @SaCheckPermission("art:schoolMajor:export")
    @Log(title = "学校专业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolMajorBo bo, HttpServletResponse response) {
        List<ArtSchoolMajorVo> list = artSchoolMajorService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校专业", ArtSchoolMajorVo.class, response);
    }

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

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

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

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