package org.dromara.system.controller;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
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.system.domain.bo.TblDzbcPathSiteBo;
import org.dromara.system.domain.vo.TblDzbcPathSiteVo;
import org.dromara.system.service.ITblDzbcPathSiteService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dzbc/pathSite")
public class TblDzbcPathSiteController extends BaseController {

    private final ITblDzbcPathSiteService tblDzbcPathSiteService;

    @GetMapping("/list")
    public TableDataInfo<TblDzbcPathSiteVo> list(TblDzbcPathSiteBo bo, PageQuery pageQuery) {
        return tblDzbcPathSiteService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/path/{pathId}")
    public R<List<TblDzbcPathSiteVo>> listByPathId(@PathVariable Long pathId) {
        return R.ok(tblDzbcPathSiteService.queryByPathId(pathId));
    }

    @Log(title = "路线站点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TblDzbcPathSiteBo bo, HttpServletResponse response) {
        List<TblDzbcPathSiteVo> list = tblDzbcPathSiteService.queryList(bo);
        ExcelUtil.exportExcel(list, "路线站点", TblDzbcPathSiteVo.class, response);
    }

    @GetMapping("/{id}")
    public R<TblDzbcPathSiteVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(tblDzbcPathSiteService.queryById(id));
    }

    @Log(title = "路线站点", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TblDzbcPathSiteBo bo) {
        return toAjax(tblDzbcPathSiteService.insertByBo(bo));
    }

    @Log(title = "路线站点", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TblDzbcPathSiteBo bo) {
        return toAjax(tblDzbcPathSiteService.updateByBo(bo));
    }

    @Log(title = "路线站点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(tblDzbcPathSiteService.deleteWithValidByIds(List.of(ids), true));
    }
}
