package org.dromara.erp.controller;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.erp.domain.ErpOrderAudit;
import org.dromara.erp.domain.vo.ErpOrderAuditVo;
import org.dromara.erp.service.IErpOrderAuditService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单审核记录控制器
 * @Author: Antigravity
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/orderAudit")
public class ErpOrderAuditController {

    private final IErpOrderAuditService erpOrderAuditService;

    /**
     * 查询审核记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpOrderAuditVo> list(ErpOrderAudit query, PageQuery pageQuery) {
        return erpOrderAuditService.queryPageList(query, pageQuery);
    }

    /**
     * 获取订单的审核历史
     */
    @GetMapping("/history/{orderId}")
    public R<List<ErpOrderAuditVo>> history(@PathVariable("orderId") String orderId) {
        return R.ok(erpOrderAuditService.queryByOrderId(orderId));
    }

    /**
     * 新增审核记录
     */
    @PostMapping("/add")
    public R<Void> add(@RequestBody ErpOrderAudit audit) {
        return erpOrderAuditService.insert(audit) ? R.ok() : R.fail();
    }
}
