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.ArtMajorVo;
import org.dromara.art.domain.bo.ArtMajorBo;
import org.dromara.art.service.IArtMajorService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 艺术专业库
 *
 * @author ZhouWenTao
 * @date 2026-02-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/major")
public class ArtMajorController extends BaseController {

    private final IArtMajorService artMajorService;

    /**
     * 查询艺术专业库列表
     */
    @SaCheckPermission("art:major:list")
    @GetMapping("/list")
    public TableDataInfo<ArtMajorVo> list(ArtMajorBo bo, PageQuery pageQuery) {
        return artMajorService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出艺术专业库列表
     */
    @SaCheckPermission("art:major:export")
    @Log(title = "艺术专业库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtMajorBo bo, HttpServletResponse response) {
        List<ArtMajorVo> list = artMajorService.queryList(bo);
        ExcelUtil.exportExcel(list, "艺术专业库", ArtMajorVo.class, response);
    }

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

    /**
     * 新增艺术专业库
     */
    @SaCheckPermission("art:major:add")
    @Log(title = "艺术专业库", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtMajorBo bo) {
        return toAjax(artMajorService.insertByBo(bo));
    }

    /**
     * 修改艺术专业库
     */
    @SaCheckPermission("art:major:edit")
    @Log(title = "艺术专业库", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtMajorBo bo) {
        return toAjax(artMajorService.updateByBo(bo));
    }

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