package com.openhis.web.pharmacymanage.controller;

import java.util.List;

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

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

import com.core.common.core.domain.R;
import com.openhis.web.pharmacymanage.appservice.ISummaryDispenseMedicineAppService;
import com.openhis.web.pharmacymanage.dto.MedicineSummarySearchParam;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 住院汇总发药
 *
 * @author yuxj
 * @date 2025/6/3
 */
@RestController
@RequestMapping("/pharmacy-manage/summary-dispense-medicine")
@Slf4j
@AllArgsConstructor
public class SummaryDispenseMedicineController {

    @Resource
    public ISummaryDispenseMedicineAppService medicineSummaryDispenseService;

    /**
     * 获取页面初始化信息
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> medicineDispenseInit() {
        return medicineSummaryDispenseService.init();
    }

    /**
     * 住院药品汇总发药单查询
     *
     * @param searchParam 查询条件
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求数据
     */
    @GetMapping("/medication_summary-list")
    public R<?> getMedicationSummaryInfo(MedicineSummarySearchParam searchParam, String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return medicineSummaryDispenseService.getMedicationSummaryInfo(searchParam, searchKey, pageNo, pageSize,
            request);
    }

    /**
     * 汇总发药
     *
     * @param searchParam 条件
     * @return 处理结果
     */
    @PutMapping("/summary-dispense-medicine")
    public R<?> SummaryDispenseMedicine(@RequestBody List<MedicineSummarySearchParam> searchParam) {
        return medicineSummaryDispenseService.SummaryDispenseMedicine(searchParam);
    }

    /**
     * 作废
     *
     * @param deliveryIdList 供应发放id
     * @param notPerformedReasonEnum 未发原因
     * @return 处理结果
     */
    @PutMapping("/dispense-cancel")
    public R<?> dispenseCancel(@RequestBody List<Long> deliveryIdList, Integer notPerformedReasonEnum) {
        return medicineSummaryDispenseService.dispenseCancel(deliveryIdList, notPerformedReasonEnum);
    }

}
