package org.dromara.system.controller.register;

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.system.domain.vo.RegisterParentsStudentVo;
import org.dromara.system.domain.bo.RegisterParentsStudentBo;
import org.dromara.system.service.IRegisterParentsStudentService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 注册-家长-学生
 *
 * @author boman
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/register/student")
public class RegisterParentsStudentController extends BaseController {

    private final IRegisterParentsStudentService registerParentsStudentService;

    /**
     * 查询注册-家长-学生列表
     */
    @SaCheckPermission("register:student:list")
    @GetMapping("/list")
    public TableDataInfo<RegisterParentsStudentVo> list(RegisterParentsStudentBo bo, PageQuery pageQuery) {
        return registerParentsStudentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出注册-家长-学生列表
     */
    @SaCheckPermission("register:student:export")
    @Log(title = "注册-家长-学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RegisterParentsStudentBo bo, HttpServletResponse response) {
        List<RegisterParentsStudentVo> list = registerParentsStudentService.queryList(bo);
        ExcelUtil.exportExcel(list, "注册-家长-学生", RegisterParentsStudentVo.class, response);
    }

    /**
     * 获取注册-家长-学生详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("register:student:query")
    @GetMapping("/{id}")
    public R<RegisterParentsStudentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(registerParentsStudentService.queryById(id));
    }

    /**
     * 新增注册-家长-学生
     */
    @SaCheckPermission("register:student:add")
    @Log(title = "注册-家长-学生", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RegisterParentsStudentBo bo) {
        return toAjax(registerParentsStudentService.insertByBo(bo));
    }

    /**
     * 修改注册-家长-学生
     */
    @SaCheckPermission("register:student:edit")
    @Log(title = "注册-家长-学生", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RegisterParentsStudentBo bo) {
        return toAjax(registerParentsStudentService.updateByBo(bo));
    }

    /**
     * 删除注册-家长-学生
     *
     * @param ids 主键串
     */
    @SaCheckPermission("register:student:remove")
    @Log(title = "注册-家长-学生", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(registerParentsStudentService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 删除注册-家长-学生
     *
     * @param bo
     */
    @SaCheckPermission("register:student:delete")
    @GetMapping("/put/delete")
    public R<Void> delete(RegisterParentsStudentBo bo) {
        return toAjax(registerParentsStudentService.deleteWithValidById(bo, true));
    }
}
