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.ArtSchoolMediaVo;
import org.dromara.art.domain.bo.ArtSchoolMediaBo;
import org.dromara.art.service.IArtSchoolMediaService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校媒体资源
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolMedia")
public class ArtSchoolMediaController extends BaseController {

    private final IArtSchoolMediaService artSchoolMediaService;

    /**
     * 查询学校媒体资源列表
     */
    @SaCheckPermission("art:schoolMedia:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolMediaVo> list(ArtSchoolMediaBo bo, PageQuery pageQuery) {
        return artSchoolMediaService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校媒体资源列表
     */
    @SaCheckPermission("art:schoolMedia:export")
    @Log(title = "学校媒体资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolMediaBo bo, HttpServletResponse response) {
        List<ArtSchoolMediaVo> list = artSchoolMediaService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校媒体资源", ArtSchoolMediaVo.class, response);
    }

    /**
     * 获取学校媒体资源详细信息
     *
     * @param mediaId 主键
     */
    @SaCheckPermission("art:schoolMedia:query")
    @GetMapping("/{mediaId}")
    public R<ArtSchoolMediaVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long mediaId) {
        return R.ok(artSchoolMediaService.queryById(mediaId));
    }

    /**
     * 新增学校媒体资源
     */
    @SaCheckPermission("art:schoolMedia:add")
    @Log(title = "学校媒体资源", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ArtSchoolMediaBo bo) {
        return toAjax(artSchoolMediaService.insertByBo(bo));
    }

    /**
     * 修改学校媒体资源
     */
    @SaCheckPermission("art:schoolMedia:edit")
    @Log(title = "学校媒体资源", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ArtSchoolMediaBo bo) {
        return toAjax(artSchoolMediaService.updateByBo(bo));
    }

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