package com.openhis.web.nenu.controller;

import java.util.List;

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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.core.common.core.domain.R;
import com.openhis.web.nenu.appservice.IGfRatioApplicationRecordAppService;
import com.openhis.web.nenu.dto.GfRatioApplicationDefinitionSelectDto;
import com.openhis.web.nenu.dto.GfRatioApplicationPrintDto;
import com.openhis.web.nenu.dto.GfRatioApplicationProcessDto;
import com.openhis.web.nenu.dto.GfRatioApplicationRecordDto;

/**
 * 公费医疗-比例调整申请记录 Controller
 *
 * @author Thanking
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/nenu/gf-ratio-application-record")
public class GfRatioApplicationRecordController {

    @Autowired
    private IGfRatioApplicationRecordAppService gfRatioApplicationRecordAppService;

    /**
     * 查询比例调整申请记录分页
     *
     * @param searchParam 查询参数
     * @param printable 申请单是否可打印
     * @param searchKey 模糊查询关键字
     * @param pageNo 页码
     * @param pageSize 行数
     * @return 比例调整申请记录分页
     */
    @GetMapping("/page")
    public R<IPage<GfRatioApplicationRecordDto>> getPage(GfRatioApplicationRecordDto searchParam,
        @RequestParam(value = "printable", defaultValue = "") String printable,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return gfRatioApplicationRecordAppService.getPage(searchParam, printable, searchKey, pageNo, pageSize);
    }

    /**
     * 查询比例调整申请记录详情
     *
     * @param id ID
     * @return 比例调整申请记录详情
     */
    @GetMapping("/{id}")
    public R<GfRatioApplicationRecordDto> getDetail(@PathVariable(value = "id") Long id) {
        return gfRatioApplicationRecordAppService.getDetail(id);
    }

    /**
     * 创建比例调整申请
     *
     * @param gfRatioApplicationRecordDto 比例调整申请记录Dto
     * @return 结果
     */
    @PostMapping
    public R<?> add(@Validated @RequestBody GfRatioApplicationRecordDto gfRatioApplicationRecordDto) {
        return gfRatioApplicationRecordAppService.add(gfRatioApplicationRecordDto);
    }

    /**
     * 取消比例调整申请
     *
     * @param id ID
     * @return 结果
     */
    @DeleteMapping("/{id}")
    public R<?> cancel(@PathVariable(value = "id") Long id) {
        return gfRatioApplicationRecordAppService.cancel(id);
    }

    /**
     * 处理比例调整申请
     *
     * @param gfRatioApplicationProcessDto 比例调整申请处理Dto
     * @return 结果
     */
    @PutMapping
    public R<?> process(@Validated @RequestBody GfRatioApplicationProcessDto gfRatioApplicationProcessDto) {
        return gfRatioApplicationRecordAppService.process(gfRatioApplicationProcessDto);
    }

    /**
     * 查询申请项目选择弹窗分页
     *
     * @param searchParam 查询参数
     * @param searchKey 模糊查询关键字
     * @param itemType 项目分类
     * @param pageNo 页码
     * @param pageSize 行数
     * @return 申请项目选择弹窗分页
     */
    @GetMapping("/definition-select-page")
    public R<IPage<GfRatioApplicationDefinitionSelectDto>> getDefinitionSelectPage(
        GfRatioApplicationDefinitionSelectDto searchParam,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "itemType") Integer itemType,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return gfRatioApplicationRecordAppService.getDefinitionSelectPage(searchParam, searchKey, itemType, pageNo,
            pageSize);
    }

    /**
     * 查询申请单打印列表
     *
     * @param ids 多个ID逗号拼接
     * @return 申请单打印列表
     */
    @GetMapping("/print-list")
    public R<List<GfRatioApplicationPrintDto>> getPrintList(@RequestParam(value = "ids") String ids) {
        return gfRatioApplicationRecordAppService.getPrintList(ids);
    }
}
