package com.openhis.web.pharmacyDispensarymanage.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.core.common.core.domain.R;
import com.openhis.common.enums.LocationForm;
import com.openhis.common.enums.SupplyType;
import com.openhis.web.pharmacyDispensarymanage.appservice.IPharmacyDispensaryCommonService;
import com.openhis.web.pharmacyDispensarymanage.appservice.IPharmacyDispensaryReceiptApprovalService;
import com.openhis.web.pharmacyDispensarymanage.appservice.IPharmacyDispensaryDispensingOrderService;
import com.openhis.web.pharmacyDispensarymanage.dto.PharmacyDispensaryDetailDto;
import com.openhis.web.pharmacyDispensarymanage.dto.PharmacyDispensarySearchParam;

import lombok.extern.slf4j.Slf4j;

/**
 * 药房发药单
 *
 * @author  yuxj
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/pharmacy-dispensary/dispensing-order")
@Slf4j
public class PharmacyDispensaryDispensingOrderController {

    @Autowired
    private IPharmacyDispensaryDispensingOrderService pharmacyDispensaryDispensingOrderService;

    @Autowired
    private IPharmacyDispensaryCommonService pharmacyDispensaryCommonService;
    @Autowired
    private IPharmacyDispensaryReceiptApprovalService pharmacyDispensaryReceiptApprovalService;
    /**
     * 发药单初始化
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> init() {
        return pharmacyDispensaryDispensingOrderService.init();
    }

    /**
     * 发药单单据列表
     *
     * @param dispensingOrderSearchParam 查询条件
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @param searchKey 模糊查询关键字
     * @param request 请求数据
     * @return 发药单据分页列表
     */
    @GetMapping(value = "/dispensing-order-page")
    public R<?> getPage(PharmacyDispensarySearchParam dispensingOrderSearchParam,
                        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                        @RequestParam(name = "searchKey", required = false) String searchKey, HttpServletRequest request) {
        return pharmacyDispensaryCommonService.getPage(dispensingOrderSearchParam, pageNo, pageSize, searchKey, request,
            "1", SupplyType.DISPENSING_ORDER.getValue());
    }
    /**
     * 发药单单据详情
     *
     * @param busNo 单据号
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 发药单单据详情
     */
    @GetMapping(value = "/dispensing-order-detail-page")
    public R<?> getDetail(@RequestParam String busNo,
                          @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return pharmacyDispensaryDispensingOrderService.getDetailPage(busNo, pageNo, pageSize);
    }
}
