package org.dromara.controller.reservRecord;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.reservRecord.bo.ReservRecordBo;
import org.dromara.domain.reservRecord.vo.ReservRecordVo;
import org.dromara.service.IReservRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约记录
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/reservRecord")
public class ReservRecordController extends BaseController {

    private final IReservRecordService reservRecordService;

    /**
     * 查询预约记录列表
     */
    @SaCheckPermission("wuYe:reservRecord:list")
    @GetMapping("/list")
    public TableDataInfo<ReservRecordVo> list(ReservRecordBo bo, PageQuery pageQuery) {
        return reservRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出预约记录列表
     */
    @SaCheckPermission("wuYe:reservRecord:export")
    @Log(title = "预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ReservRecordBo bo, HttpServletResponse response) {
        List<ReservRecordVo> list = reservRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "预约记录", ReservRecordVo.class, response);
    }

    /**
     * 获取预约记录详细信息
     *
     * @param reservRecordId 主键
     */
    @SaCheckPermission("wuYe:reservRecord:query")
    @GetMapping("/{reservRecordId}")
    public R<ReservRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long reservRecordId) {
        return R.ok(reservRecordService.queryById(reservRecordId));
    }

    /**
     * 新增预约记录
     */
    @SaCheckPermission("wuYe:reservRecord:add")
    @Log(title = "预约记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ReservRecordBo bo) {
        return toAjax(reservRecordService.insertByBo(bo));
    }

    /**
     * 修改预约记录
     */
    @SaCheckPermission("wuYe:reservRecord:edit")
    @Log(title = "预约记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ReservRecordBo bo) {
        return toAjax(reservRecordService.updateByBo(bo));
    }

    /**
     * 删除预约记录
     *
     * @param reservRecordIds 主键串
     */
    @SaCheckPermission("wuYe:reservRecord:remove")
    @Log(title = "预约记录", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{reservRecordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] reservRecordIds) {
        return toAjax(reservRecordService.deleteWithValidByIds(List.of(reservRecordIds), true));
    }
}
