package com.openhis.web.datadictionary.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.core.common.core.domain.R;
import com.openhis.web.datadictionary.appservice.IDiagTreatMAppService;
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentSelParam;
import com.openhis.web.datadictionary.dto.DiagnosisTreatmentUpDto;

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

/**
 * TODO:诊疗目录
 *
 * @author lpt
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/data-dictionary/diagnosis-treatment")
@Slf4j
@AllArgsConstructor
public class DiagnosisTreatmentController {

    @Resource
    private IDiagTreatMAppService diagTreatMAppService;

    /**
     * 诊疗目录初期查询
     *
     * @return
     */
    @GetMapping("/init")
    public R<?> getDiseaseTreatmentInit() {
        return diagTreatMAppService.getDiseaseTreatmentInit();
    }

    /**
     * 查询诊疗目录分页列表
     *
     * @param DiagnosisTreatmentSelParam 查询条件
     * @param searchKey 查询条件-模糊查询
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return
     */
    @GetMapping("/information-page")
    public R<?> getDiseaseTreatmentPage(DiagnosisTreatmentSelParam DiagnosisTreatmentSelParam,
        @RequestParam(value = "searchKey", defaultValue = "") String searchKey,
        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        return diagTreatMAppService.getDiseaseTreatmentPage(DiagnosisTreatmentSelParam, searchKey, pageNo, pageSize,
            request);
    }

    /**
     * 根据id查询诊疗详情
     *
     * @param id 诊疗ID
     * @return
     */
    @GetMapping("/information-one")
    public R<?> getDiseaseTreatmentOne(@RequestParam Long id) {
        return diagTreatMAppService.getDiseaseTreatmentOne(id);
    }

    /**
     * 诊疗目录编辑
     *
     * @param diagnosisTreatmentUpDto 诊疗目录列表
     * @return
     */
    @PutMapping("/information")
    public R<?> editDiseaseTreatment(@RequestBody DiagnosisTreatmentUpDto diagnosisTreatmentUpDto) {
        return diagTreatMAppService.editDiseaseTreatment(diagnosisTreatmentUpDto);
    }

    /**
     * 诊疗目录停用
     *
     * @param ids 诊疗目录ID列表
     * @return
     */
    @PutMapping("/information-stop")
    public R<?> editDiseaseTreatmentStop(@RequestBody List<Long> ids) {
        return diagTreatMAppService.editDiseaseTreatmentStop(ids);
    }

    /**
     * 诊疗目录启用
     *
     * @param ids 诊疗目录ID列表
     * @return
     */
    @PutMapping("/information-start")
    public R<?> editDiseaseTreatmentStart(@RequestBody List<Long> ids) {
        return diagTreatMAppService.editDiseaseTreatmentStart(ids);
    }

    /**
     * 新增诊疗目录
     *
     * @param diagnosisTreatmentUpDto 诊疗目录
     * @return
     */
    @PostMapping("/information")
    public R<?> addDiseaseTreatment(@Validated @RequestBody DiagnosisTreatmentUpDto diagnosisTreatmentUpDto) {
        return diagTreatMAppService.addDiseaseTreatment(diagnosisTreatmentUpDto);
    }

    /**
     * 导入诊疗目录
     *
     * @param file 文件
     * @return 结果
     */
    @PostMapping("/import-data")
    public R<?> importData(MultipartFile file) {
        return diagTreatMAppService.importData(file);
    }

    /**
     * 获取导入模板
     *
     * @param response 响应
     */
    @PostMapping("/import-template")
    public void importTemplate(HttpServletResponse response) {
        diagTreatMAppService.importTemplate(response);
    }

    /**
     * 校验诊疗项目是否可以编辑
     *
     * @param activityId 诊疗ID
     * @return 校验结果
     */
    @GetMapping("/validate-edit")
    public R<?> validateActivityEdit(Long activityId) {
        return diagTreatMAppService.validateActivityEdit(activityId);
    }
}
