package org.dromara.erp.controller;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.erp.domain.query.ErpOrderDetailQuery;
import org.dromara.erp.domain.vo.ErpOrderDetailVo;
import org.dromara.erp.service.IErpOrderDetailService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单明细控制器
 *
 * @Author: Antigravity
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/orderDetail")
public class ErpOrderDetailController {

    private final IErpOrderDetailService erpOrderDetailService;

    /**
     * 根据订单ID查询明细列表
     */
    @GetMapping("/list")
    public R<List<ErpOrderDetailVo>> list(ErpOrderDetailQuery query) {
        return R.ok(erpOrderDetailService.queryList(query));
    }

    /**
     * 获取订单明细详情
     */
    @GetMapping("/{rowId}")
    public R<ErpOrderDetailVo> getInfo(@PathVariable("rowId") String rowId) {
        return R.ok(erpOrderDetailService.queryById(rowId));
    }

    /**
     * 新增订单明细
     */
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@RequestBody org.dromara.erp.domain.bo.ErpOrderDetailBo bo) {
        return erpOrderDetailService.insert(bo) ? R.ok() : R.fail();
    }

    /**
     * 修改订单明细
     */
    @RepeatSubmit()
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody org.dromara.erp.domain.bo.ErpOrderDetailBo bo) {
        return erpOrderDetailService.update(bo) ? R.ok() : R.fail();
    }

    /**
     * 删除订单明细
     */
    @RepeatSubmit()
    @DeleteMapping("/{rowId}")
    public R<Void> remove(@PathVariable("rowId") String rowId) {
        return erpOrderDetailService.deleteById(rowId) ? R.ok() : R.fail();
    }

    /**
     * 批量修改订单明细（表面处理 / 包装方式）
     *
     * @Author: Trae
     */
    @RepeatSubmit()
    @PutMapping("/batchUpdate")
    public R<Void> batchUpdate(@RequestBody org.dromara.erp.domain.bo.ErpOrderDetailBatchUpdateBo bo) {
        return erpOrderDetailService.batchUpdate(bo) ? R.ok() : R.fail();
    }

}
