package com.openhis.web.departmentmanage.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.SupplyType;
import com.openhis.web.departmentmanage.appservice.IDepartmentCommonService;
import com.openhis.web.departmentmanage.appservice.IDepartmentReceiptApprovalService;
import com.openhis.web.departmentmanage.appservice.IDepartmentIssuanceOrderService;
import com.openhis.web.departmentmanage.dto.DepartmentDetailDto;
import com.openhis.web.departmentmanage.dto.DepartmentSearchParam;

import lombok.extern.slf4j.Slf4j;

/**
 * 科室材料发出单
 *
 * @author  yuxj
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/department/issuance-order")
@Slf4j
public class DepartmentIssuanceOrderController {

    @Autowired
    private IDepartmentIssuanceOrderService departmentIssuanceOrderService;

    @Autowired
    private IDepartmentCommonService departmentCommonService;

    @Autowired
    private IDepartmentReceiptApprovalService departmentReceiptApprovalService;
    /**
     * 发出单初始化
     *
     * @return 初始化信息
     */
    @GetMapping(value = "/init")
    public R<?> init() {
        return departmentIssuanceOrderService.init();
    }

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