package com.ruoyi.web.modules.architecture.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.modules.architecture.service.IAppMedicationDrugService;
import com.ruoyi.web.modules.architecture.service.IAppMedicationWithdrawalService;

/**
 * 移动端用药工具 — 计算休药期。
 */
@RestController
@RequestMapping("/app/medication/withdrawal")
public class BizAppMedicationWithdrawalController extends BaseController
{
    @Autowired
    private IAppMedicationDrugService appMedicationDrugService;

    @Autowired
    private IAppMedicationWithdrawalService appMedicationWithdrawalService;

    /**
     * 药物名称下拉（与「查询药物」相同数据源）。
     */
    @GetMapping("/names")
    public AjaxResult drugNames(@RequestParam(value = "keyword", required = false) String keyword)
    {
        return success(appMedicationDrugService.selectDrugNameOptions(keyword));
    }

    /**
     * 计算期满日期：停药日期 + 休药期天数。
     */
    @GetMapping("/calculate")
    public AjaxResult calculate(
            @RequestParam("drugName") String drugName,
            @RequestParam("stopDate") String stopDate)
    {
        return success(appMedicationWithdrawalService.calculate(drugName, stopDate));
    }
}
