package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.entity.SymptomRecord;
import com.example.service.SymptomRecordService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 症状记录控制器
 */
@RestController
@RequestMapping("/symptomRecord")
public class SymptomRecordController {

    @Resource
    private SymptomRecordService symptomRecordService;

    /**
     * 添加症状记录
     */
    @PostMapping
    public Result add(@RequestBody SymptomRecord symptomRecord) {
        symptomRecordService.add(symptomRecord);
        return Result.success();
    }

    /**
     * 更新症状记录
     */
    @PutMapping
    public Result update(@RequestBody SymptomRecord symptomRecord) {
        symptomRecordService.update(symptomRecord);
        return Result.success();
    }

    /**
     * 删除症状记录
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        symptomRecordService.delete(id);
        return Result.success();
    }

    /**
     * 根据ID查询症状记录
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        SymptomRecord symptomRecord = symptomRecordService.getById(id);
        return Result.success(symptomRecord);
    }

    /**
     * 根据患者ID查询症状记录
     */
    @GetMapping("/patient/{patientId}")
    public Result getByPatientId(@PathVariable Integer patientId) {
        List<SymptomRecord> list = symptomRecordService.getByPatientId(patientId);
        return Result.success(list);
    }

    /**
     * 查询当前登录患者的症状记录
     */
    @GetMapping("/my")
    public Result getMyRecords() {
        List<SymptomRecord> list = symptomRecordService.getByPatientId(null);
        return Result.success(list);
    }

    /**
     * 分页查询症状记录
     */
    @GetMapping("/selectPage")
    public Result selectPage(
            @RequestParam(required = false) String patientName,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        SymptomRecord symptomRecord = new SymptomRecord();
        symptomRecord.setPatientName(patientName);
        com.github.pagehelper.PageInfo<SymptomRecord> pageInfo = symptomRecordService.selectPage(symptomRecord, pageNum, pageSize, startDate, endDate);
        return Result.success(pageInfo);
    }
} 