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.TblDzbcSitePriceBo;
import org.dromara.system.domain.vo.TblDzbcSitePriceVo;
import org.dromara.system.service.ITblDzbcSitePriceService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    private final ITblDzbcSitePriceService tblDzbcSitePriceService;

    @GetMapping("/list")
    public TableDataInfo<TblDzbcSitePriceVo> list(TblDzbcSitePriceBo bo, PageQuery pageQuery) {
        return tblDzbcSitePriceService.queryPageList(bo, pageQuery);
    }

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

    @Log(title = "站点价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TblDzbcSitePriceBo bo, HttpServletResponse response) {
        List<TblDzbcSitePriceVo> list = tblDzbcSitePriceService.queryList(bo);
        ExcelUtil.exportExcel(list, "站点价格", TblDzbcSitePriceVo.class, response);
    }

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

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

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

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