package com.openhis.web.inventorymanage.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.core.common.utils.StringUtils;
import com.openhis.web.adjustprice.appservice.IAdjustPriceService;
import com.openhis.web.adjustprice.dto.AdjustPriceManagerSearchParam;
import com.openhis.web.inventorymanage.appservice.IInventoryAdjustPriceService;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName AdjustPriceController
 * @Description TODO
 * @Author raymond
 * @Date 2025/10/23 14:47
 * @Version 1.0
 **/
@RestController
@RequestMapping("/inventory-examine-page")
@Slf4j
public class PriceAdjustmentFormController {

    @Resource
    private IInventoryAdjustPriceService inventoryAdjustPriceService;
    @Resource
    private IAdjustPriceService adjustPriceService;

    @GetMapping(value = "/init")
    public R<?> receiptApprovalInit() {
        return inventoryAdjustPriceService.adjustPriceInit();
    }

    /**
     * Desc: 查询所有未提交的调价单集合
     *
     * @param
     * @Author raymond
     * @Date 16:55 2025/10/15
     * @return com.core.common.core.domain.R<?>
     **/
    @GetMapping(value = "getPageByExamine")
    public R<?> getPageByExamine(AdjustPriceManagerSearchParam adjustPriceManagerSearchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return this.inventoryAdjustPriceService.getPageByExamineList(adjustPriceManagerSearchParam, pageNo, pageSize,
            searchKey, request);
    }

    /**
     * Desc: 根据单据号 进行审核通过操作
     *
     * @param busNo
     * @Author raymond
     * @Date 18:09 2025/10/18
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "updateExamineByApproved")
    public R<?> updateExamineByApproved(@RequestParam String busNo) {
        return this.inventoryAdjustPriceService.updateExamineByApproved(busNo);
    }

    /**
     * Desc: 根据单据号 进行审核驳回操作
     *
     * @param busNo
     * @Author raymond
     * @Date 19:24 2025/10/18
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "updateExamineByRejected")
    public R<?> updateExamineByRejected(@RequestParam String busNo) {
        return this.inventoryAdjustPriceService.updateExamineByRejected(busNo);
    }

    /**
     * Desc: 根据 单据号 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchSupplyRequestByMed")
    public R<?> searchSupplyRequestByMed(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByMed(busNo);
    }

    /**
     * Desc: 根据 单据号 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchSupplyRequestByDevice")
    public R<?> searchSupplyRequestByDevice(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByDevice(busNo);
    }

    /**
     * Desc: 根据 单据号 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchSupplyRequestByActivity")
    public R<?> searchSupplyRequestByActivity(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByActivity(busNo);
    }

    /**
     * Desc: 根据 单据号 查询详情
     *
     * @param busNo
     * @Author raymond
     * @Date 12:01 2025/10/21
     * @return com.core.common.core.domain.R<?>
     **/
    @PostMapping(value = "searchSupplyRequestByHealth")
    public R<?> searchSupplyRequestByHealth(@RequestParam String busNo) {
        if (StringUtils.isEmpty(busNo)) {
            return R.fail();
        }
        return this.adjustPriceService.searchChangePriceDataByHealth(busNo);
    }

}
