/*
 * Copyright ©2023 CJB-CNIT Team. All rights reserved
 */
package com.openhis.web.personalization.controller;

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

import com.core.common.core.domain.R;
import com.openhis.common.enums.BindingType;
import com.openhis.web.personalization.appservice.IOrdersGroupPackageAppService;
import com.openhis.web.personalization.dto.OrdersGroupPackageSaveDto;

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

/**
 * 组合套餐 controller
 *
 * @author yangmo
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/personalization/orders-group-package")
@Slf4j
@AllArgsConstructor
public class OrdersGroupPackageController {

    private final IOrdersGroupPackageAppService ordersGroupPackageAppService;

    /**
     * 保存个人组套
     * 
     * @param ordersGroupPackageSaveDto 组合套餐保存dto
     * @return 结果
     */
    @PostMapping(value = "/save-personal")
    public R<?> savePersonal(@RequestBody OrdersGroupPackageSaveDto ordersGroupPackageSaveDto) {
        return ordersGroupPackageAppService.saveGroupPackage(ordersGroupPackageSaveDto,
            BindingType.PERSONAL.getValue());
    }

    /**
     * 保存科室组套
     *
     * @param ordersGroupPackageSaveDto 组合套餐保存dto
     * @return 结果
     */
    @PostMapping(value = "/save-organization")
    public R<?> saveOrganization(@RequestBody OrdersGroupPackageSaveDto ordersGroupPackageSaveDto) {
        return ordersGroupPackageAppService.saveGroupPackage(ordersGroupPackageSaveDto,
            BindingType.ORGANIZATION.getValue());
    }

    /**
     * 保存全院组套
     *
     * @param ordersGroupPackageSaveDto 组合套餐保存dto
     * @return 结果
     */
    @PostMapping(value = "/save-hospital")
    public R<?> saveHospital(@RequestBody OrdersGroupPackageSaveDto ordersGroupPackageSaveDto) {
        return ordersGroupPackageAppService.saveGroupPackage(ordersGroupPackageSaveDto,
            BindingType.HOSPITAL.getValue());
    }

    /**
     * 查询个人组套
     * 
     * @param searchKey 模糊查询关键字
     * @return 个人组套
     */
    @GetMapping(value = "/get-personal")
    public R<?> getPersonal(@RequestParam(value = "searchKey", defaultValue = "") String searchKey) {
        return R.ok(ordersGroupPackageAppService.getGroupPackage(BindingType.PERSONAL.getValue(), searchKey));
    }

    /**
     * 查询科室组套
     * 
     * @param searchKey 模糊查询关键字
     * @return 科室组套
     */
    @GetMapping(value = "/get-organization")
    public R<?> getOrganization(@RequestParam(value = "searchKey", defaultValue = "") String searchKey) {
        return R.ok(ordersGroupPackageAppService.getGroupPackage(BindingType.ORGANIZATION.getValue(), searchKey));
    }

    /**
     * 查询全院组套
     * 
     * @param searchKey 模糊查询关键字
     * @return 全院组套
     */
    @GetMapping(value = "/get-hospital")
    public R<?> getHospital(@RequestParam(value = "searchKey", defaultValue = "") String searchKey) {
        return R.ok(ordersGroupPackageAppService.getGroupPackage(BindingType.HOSPITAL.getValue(), searchKey));
    }

    /**
     * 查询组合套餐明细
     * 
     * @param groupPackageId 组合套餐id
     * @return 组合套餐明细
     */
    @GetMapping(value = "/get-group-package-detail")
    public R<?> getGroupPackageDetail(@RequestParam Long groupPackageId) {
        return R.ok(ordersGroupPackageAppService.getGroupPackageDetail(groupPackageId));
    }

    /**
     * 删除组合套餐
     * 
     * @param groupPackageId 组合套餐id
     * @return 结果
     */
    @DeleteMapping(value = "/group-package-detail")
    public R<?> delGroupPackage(@RequestParam Long groupPackageId) {
        return ordersGroupPackageAppService.delGroupPackage(groupPackageId);
    }

    /**
     * 查询组合套餐,供开立医嘱使用
     * 
     * @param organizationId 患者挂号对应的科室id
     * @return 组合套餐
     */
    @GetMapping(value = "/group-package-for-order")
    public R<?>
        getGroupPackageForOrder(@RequestParam(value = "organizationId", defaultValue = "0") Long organizationId) {
        return R.ok(ordersGroupPackageAppService.getGroupPackageForOrder(organizationId));
    }

}
