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

import javax.servlet.http.HttpServletRequest;

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

import com.core.common.core.domain.R;
import com.openhis.web.inhospitalcharge.appservice.IAdvancePaymentManageAppService;
import com.openhis.web.inhospitalcharge.dto.AdvancePaymentInAndOutDto;
import com.openhis.web.inhospitalcharge.dto.AdvancePaymentInfoDto;

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

/**
 * 预交金管理 controller
 */
@RestController
@RequestMapping("/inhospital-charge/advance-payment")
@Slf4j
@AllArgsConstructor
public class AdvancePaymentManageController {

    private final IAdvancePaymentManageAppService iAdvancePaymentManageAppService;

    /**
     * 查询患者预交金基本信息
     *
     * @param advancePaymentInfoDto 患者预交金基本信息dto
     * @param searchKey 模糊查询关键字
     * @param pageNo 当前页
     * @param pageSize 每页多少条
     * @param request 请求
     * @return 患者预交金基本信息
     */
    @GetMapping(value = "/advance-payment-info")
    public R<?> getAdvancePaymentInfo(AdvancePaymentInfoDto advancePaymentInfoDto,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return R.ok(iAdvancePaymentManageAppService.getAdvancePaymentInfo(advancePaymentInfoDto, searchKey, pageNo,
            pageSize, request));
    }

    /**
     * 查询预交金支付流水记录
     *
     * @param encounterId 住院就诊Id
     * @return 预交金支付流水记录
     */
    @GetMapping(value = "/advance-payment-flow")
    public R<?> getAdvancePaymentFlowRecord(@RequestParam Long encounterId) {
        return R.ok(iAdvancePaymentManageAppService.getAdvancePaymentFlowRecord(encounterId));
    }

    /**
     * 预交金交款
     * 
     * @param advancePaymentInAndOutDto 交款dto
     * @return 结果
     */
    @PostMapping(value = "/in-advance-payment")
    public R<?> inAdvancePayment(@RequestBody AdvancePaymentInAndOutDto advancePaymentInAndOutDto) {
        return iAdvancePaymentManageAppService.inAdvancePayment(advancePaymentInAndOutDto);
    }

    /**
     * 预交金退款
     *
     * @param advancePaymentInAndOutDto 退款dto
     * @return 结果
     */
    @PostMapping(value = "/out-advance-payment")
    public R<?> outAdvancePayment(@RequestBody AdvancePaymentInAndOutDto advancePaymentInAndOutDto) {
        return iAdvancePaymentManageAppService.outAdvancePayment(advancePaymentInAndOutDto);
    }

}
