package com.lemon.lifecenter.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lemon.lifecenter.dto.PatientPHRHistoryDTO;
import com.lemon.lifecenter.dto.PatientPHRLatestDTO;
import com.lemon.lifecenter.dto.PatientSymptomSimDTO;
import com.lemon.lifecenter.mapper.PatientPHRHistoryMapper;
import com.lemon.lifecenter.mapper.PatientPHRLatestMapper;
import com.lemon.lifecenter.mapper.PatientSymptomSimMapper;

@Service
public class PHRService {

	@Autowired
	private PatientPHRHistoryMapper mapperHistory;
	
	@Autowired
	private PatientPHRLatestMapper mapperPHRLatest;
	
	@Autowired
	private PatientSymptomSimMapper mapperSymptom;
	
	public void insertPHR(PatientPHRHistoryDTO dto) {
		mapperHistory.insertPHRHistory(dto);
		
		PatientPHRLatestDTO phrLatestDTO = new PatientPHRLatestDTO();
		phrLatestDTO.setPatientIdx(dto.getPatientIdx());
		
		switch (dto.getPhrType()) {
			case "temperature":
				phrLatestDTO.setTemperature(dto.getPhrValue());
				break;
			case "oxygenSaturation":
				phrLatestDTO.setOxygenSaturation((int) dto.getPhrValue());
				break;
			case "pulseRate":
				phrLatestDTO.setPulseRate((int) dto.getPhrValue());
				break;
			case "systolicBloodPressure":
				phrLatestDTO.setSystolicBloodPressure((int) dto.getPhrValue());
				break;
			case "diastolicBloodPressure":
				phrLatestDTO.setDiastolicBloodPressure((int) dto.getPhrValue());
				break;
			case "bloodSugar":
				phrLatestDTO.setBloodSugar((int) dto.getPhrValue());
				break;
		}
		
		mapperPHRLatest.insertPHRLatest(phrLatestDTO);		
	}
	
	public int selectPHRHistoryCount(PatientPHRHistoryDTO dto) {
        return mapperHistory.selectPHRHistoryCount(dto);
    }
    
    public List<PatientPHRHistoryDTO> selectPHRHistoryList(PatientPHRHistoryDTO dto) {
        return mapperHistory.selectPHRHistoryList(dto);
    }
    
    public void insertSymptom(PatientSymptomSimDTO dto) {
    	mapperSymptom.insertSymptom(dto);
    }
    
    public int selectSymptomCount(PatientSymptomSimDTO dto) {
        return mapperSymptom.selectSymptomCount(dto);
    }
    
    public List<PatientSymptomSimDTO> selectSymptomList(PatientSymptomSimDTO dto) {
        return mapperSymptom.selectSymptomList(dto);
    }
}
