package com.openhis.web.adjustprice.controller;

import com.core.common.core.domain.R;
import com.core.common.enums.TenantOptionDict;
import com.core.web.util.TenantOptionUtil;
import com.openhis.common.enums.OrderPricingSource;
import com.openhis.web.adjustprice.appservice.IAdjustPriceService;
import com.openhis.web.adjustprice.dto.AdjustPriceDataVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ChargePriceController
 * @Description 调价修改药品、耗材、诊疗、挂号接口类
 * @Author raymond
 * @Date 2025/10/14 16:56
 * @Version 1.0
 **/
@RestController
@RequestMapping("/change/price")
public class ChangePriceController {

    @Resource
    private IAdjustPriceService adjustPriceService;

    /**
     * Desc: 根据关键词搜索数据
     *
     * @param
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 09:26 2025/10/20
     **/
    @PostMapping(value = "searchKeyWordDataListByMed")
    public R<?> searchKeyWordDataListByMed(@RequestParam(name = "searchKey", required = false) String searchKey) {
        return R.ok(this.adjustPriceService.searchKeyWordDataListByMed(searchKey));
    }

    /**
     * Desc: 根据关键词搜索数据
     *
     * @param
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 09:26 2025/10/20
     **/
    @PostMapping(value = "searchKeyWordDataListByDevice")
    public R<?> searchKeyWordDataListByDevice(@RequestParam(name = "searchKey", required = false) String searchKey) {
        return R.ok(this.adjustPriceService.searchKeyWordDataListByDevice(searchKey));
    }

    /**
     * Desc: 根据关键词搜索数据
     *
     * @param
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 09:26 2025/10/20
     **/
    @PostMapping(value = "searchKeyWordDataListByActivity")
    public R<?> searchKeyWordDataListByActivity(@RequestParam(name = "searchKey", required = false) String searchKey) {
        return R.ok(this.adjustPriceService.searchKeyWordDataListByActivity(searchKey));
    }

    /**
     * Desc: 查询所有 有挂号信息的科室
     *
     * @param
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 08:38 2025/10/22
     **/
    @PostMapping(value = "searchAllOrgData")
    public R<?> searchAllOrgData() {
        return this.adjustPriceService.searchAllOrgData();
    }

    /**
     * Desc: 根据科室id 加载 挂号信息
     *
     * @param orgId
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 16:46 2025/10/22
     **/
    @PostMapping(value = "searchHealthData")
    public R<?> searchHealthData(@RequestParam Long orgId) {
        return this.adjustPriceService.searchHealthData(orgId);
    }

    /**
     * Desc: 保存 改价数据
     *
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 08:47 2025/10/15
     **/
    @PostMapping(value = "commitChangePriceData")
    public R<?> commitChangePriceData(@RequestBody List<AdjustPriceDataVo> dataVoList) {
        return adjustPriceService.submitChangePriceData(dataVoList);
    }

    /**
     * Desc: 根据供应商和药品名称加载要修改的药品数据
     *
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 08:47 2025/10/15
     **/
    @PostMapping(value = "submitExamineChangePriceData")
    public R<?> submitExamineChangePriceData(@RequestBody List<AdjustPriceDataVo> dataVoList) {
        return adjustPriceService.submitExamineChangePriceData(dataVoList);
    }

    /**
     * Desc: 根据货品ID 查询是否有审核中的药品数据
     *
     * @param itemId
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 17:32 2025/11/3
     **/
    @PostMapping(value = "checkMedApprovalExist")
    public R<?> checkMedApprovalExist(@RequestParam Long itemId) {
        return this.adjustPriceService.checkMedApprovalExist(itemId);
    }

    /**
     * Desc: 根据货品ID 查询是否有审核中的药品数据
     *
     * @param itemId
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 17:32 2025/11/3
     **/
    @PostMapping(value = "checkDeviceApprovalExist")
    public R<?> checkDeviceApprovalExist(@RequestParam Long itemId) {
        return this.adjustPriceService.checkDeviceApprovalExist(itemId);
    }

    /**
     * Desc: 根据货品ID 查询是否有审核中的药品数据
     *
     * @param itemId
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 17:32 2025/11/3
     **/
    @PostMapping(value = "checkActivityApprovalExist")
    public R<?> checkActivityApprovalExist(@RequestParam Long itemId) {
        return this.adjustPriceService.checkActivityApprovalExist(itemId);
    }

    /**
     * Desc: 根据货品ID 查询是否有审核中的药品数据
     *
     * @param itemId
     * @return com.core.common.core.domain.R<?>
     * @Author raymond
     * @Date 17:32 2025/11/3
     **/
    @PostMapping(value = "checkHealthApprovalExist")
    public R<?> checkHealthApprovalExist(@RequestParam Long itemId) {
        return this.adjustPriceService.checkHealthApprovalExist(itemId);
    }

    /**
     * Desc: 查询调价控制开关状态接口
     *
     * @return true:统一零售价 , false:按批次号售卖
     **/
    @GetMapping(value = "getAdjustPriceSwitchState")
    public R<?> getAdjustPriceSwitchState() {
        // 医嘱定价来源
        String orderPricingSource = TenantOptionUtil.getOptionContent(TenantOptionDict.ORDER_PRICING_SOURCE);
        if (OrderPricingSource.RETAIL_PRICE.getCode().equals(orderPricingSource)) {
            return R.ok(true);
        }
        return R.ok(false);
    }
}
