package com.openhis.web.inhospitalnursestation.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.inhospitalnursestation.appservice.IMedicineSummaryAppService;
import com.openhis.web.inhospitalnursestation.dto.DispenseFormSearchParam;
import com.openhis.web.inhospitalnursestation.dto.MedicineSummaryParam;

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

/**
 * 住院领药
 *
 * @author yuxj
 * @date 2025/8/18
 */
@RestController
@RequestMapping("/nurse-station/medicine-summary")
@Slf4j
@AllArgsConstructor
public class MedicineSummaryController {

    @Resource
    public IMedicineSummaryAppService medicineSummaryAppService;

    /**
     * 查询发药单信息
     *
     * @param dispenseFormSearchParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param request 请求
     * @return 发药单信息
     */
    @GetMapping(value = "/dispensing-form")
    public R<?> getMedicineDispenseFormPage(DispenseFormSearchParam dispenseFormSearchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return medicineSummaryAppService.getMedicineDispenseFormPage(dispenseFormSearchParam, pageNo, pageSize,
            request);
    }

    /**
     * 查询药品汇总单
     *
     * @param dispenseFormSearchParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param searchKey 模糊查询关键字
     * @param request 请求
     * @return 药品汇总单
     */
    @GetMapping(value = "/summary-form")
    public R<?> getMedicineSummaryFormPage(DispenseFormSearchParam dispenseFormSearchParam,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, String searchKey,
        HttpServletRequest request) {
        return medicineSummaryAppService.getMedicineSummaryFormPage(dispenseFormSearchParam, pageNo, pageSize,
            searchKey, request);
    }

    /**
     * 查询药品汇总单详情
     *
     * @param summaryNo 汇总单号
     * @return 药品汇总单详情
     */
    @GetMapping(value = "/summary-form-detail")
    public R<?> getMedicineSummaryFormDetail(String summaryNo) {
        return medicineSummaryAppService.getMedicineSummaryFormDetail(summaryNo);
    }

    /**
     * 生成汇总发药单
     *
     * @param medicineSummaryParamList 汇总发药申请参数
     * @return 处理结果
     */
    @PostMapping("/medicine-summary")
    public R<?> medicineSummary(@RequestBody List<MedicineSummaryParam> medicineSummaryParamList) {
        return medicineSummaryAppService.medicineSummary(medicineSummaryParamList);
    }

    /**
     * 取消汇总
     *
     * @param summaryNo 汇总单号
     * @return 处理结果
     */
    @PutMapping("/cancel-summary")
    public R<?> cancelSummary(String summaryNo) {
        return medicineSummaryAppService.cancelSummary(summaryNo);
    }
}
