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.ArtSchoolCampusVo;
import org.dromara.art.domain.bo.ArtSchoolCampusBo;
import org.dromara.art.service.IArtSchoolCampusService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 学校校区
 *
 * @author ZhouWenTao
 * @date 2026-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/art/schoolCampus")
public class ArtSchoolCampusController extends BaseController {

    private final IArtSchoolCampusService artSchoolCampusService;

    /**
     * 查询学校校区列表
     */
    @SaCheckPermission("art:schoolCampus:list")
    @GetMapping("/list")
    public TableDataInfo<ArtSchoolCampusVo> list(ArtSchoolCampusBo bo, PageQuery pageQuery) {
        return artSchoolCampusService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出学校校区列表
     */
    @SaCheckPermission("art:schoolCampus:export")
    @Log(title = "学校校区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ArtSchoolCampusBo bo, HttpServletResponse response) {
        List<ArtSchoolCampusVo> list = artSchoolCampusService.queryList(bo);
        ExcelUtil.exportExcel(list, "学校校区", ArtSchoolCampusVo.class, response);
    }

    /**
     * 获取学校校区详细信息
     *
     * @param campusId 主键
     */
    @SaCheckPermission("art:schoolCampus:query")
    @GetMapping("/{campusId}")
    public R<ArtSchoolCampusVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long campusId) {
        return R.ok(artSchoolCampusService.queryById(campusId));
    }

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

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

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