using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MeteoWebApp.Models
{
	public class Measurement
	{
		[Key]
		public int MeasurementId { get; set; }
		public int StationId { get; set; }
		public DateTime Timestamp { get; set; }
		public float Temperature { get; set; }
		public float DewPoint { get; set; }
		public float TemperatureFeelsLike { get; set; }
		public float Humidity { get; set; }
		public float Pressure { get; set; }
		public float SeaLevelPressure { get; set; }
		public float WindSpeed { get; set; }
		public float WindAngle { get; set; }
		[StringLength(3)]
		public string WindAngleStr { get; set; }
		public float RainAmount { get; set; }
		public float UvIndex { get; set; }
		[StringLength(16)]
		public string SoilTempDepth1 { get; set; }
		public float SoilTemp1 { get; set; }
		[StringLength(16)]
		public string SoilTempDepth2 { get; set; }
		public float SoilTemp2 { get; set; }
		[StringLength(16)]
		public string SoilTempDepth3 { get; set; }
		public float SoilTemp3 { get; set; }
		[StringLength(16)]
		public string SoilMoistureDepth1 { get; set; }
		public float SoilMoisture1 { get; set; }
		[StringLength(16)]
		public string SoilMoistureDepth2 { get; set; }
		public float SoilMoisture2 { get; set; }
		[StringLength(16)]
		public string SoilMoistureDepth3 { get; set; }
		public float SoilMoisture3 { get; set; }
		public float BatteryVoltage { get; set; }

		[ForeignKey("StationId")]
		public virtual Station Station { get; set; }

		/* Contructor */
		public Measurement()
		{
		}

		/* Contructor - fill data from parameters */
		public Measurement(StationData stationData, int StationId)
		{
			//this.MeasurementId is automatically incremented in database
			this.StationId = StationId;
			this.Timestamp = DateTime.Now;
			this.Temperature = stationData.Temperature;
			this.DewPoint = stationData.DewPoint;
			this.TemperatureFeelsLike = stationData.TemperatureFeelsLike;
			this.Humidity = stationData.Humidity;
			this.Pressure = stationData.Pressure;
			this.SeaLevelPressure = stationData.SeaLevelPressure;
			this.WindSpeed = stationData.WindSpeed;
			this.WindAngle = stationData.WindAngle;
			this.WindAngleStr = stationData.WindAngleStr;
			this.RainAmount = stationData.RainAmount;
			this.UvIndex = stationData.UvIndex;
			this.SoilTempDepth1 = stationData.SoilTempDepth1;
			this.SoilTemp1 = stationData.SoilTemp1;
			this.SoilTempDepth2 = stationData.SoilTempDepth2;
			this.SoilTemp2 = stationData.SoilTemp2;
			this.SoilTempDepth3 = stationData.SoilTempDepth3;
			this.SoilTemp3 = stationData.SoilTemp3;
			this.SoilMoistureDepth1 = stationData.SoilMoistureDepth1;
			this.SoilMoisture1 = stationData.SoilMoisture1;
			this.SoilMoistureDepth2 = stationData.SoilMoistureDepth2;
			this.SoilMoisture2 = stationData.SoilMoisture2;
			this.SoilMoistureDepth3 = stationData.SoilMoistureDepth3;
			this.SoilMoisture3 = stationData.SoilMoisture3;
			this.BatteryVoltage = stationData.BatteryVoltage;
		}

		/* Translate wind angle string property to czech */
		public string WindAngleStrCzech()
		{
			switch (this.WindAngleStr)
			{
				case "N":		
					return "S";
				case "NNE":
					return "SSV";
				case "NE":
					return "SV";
				case "ENE":
					return "VSV";
				case "E":
					return "V";
				case "ESE":
					return "VJV";
				case "SE":
					return "JV";
				case "SSE":
					return "JJV";
				case "S":
					return "J";
				case "SSW":
					return "JJZ";
				case "SW":
					return "JZ";
				case "WSW":
					return "ZJZ";
				case "W":
					return "Z";
				case "WNW":
					return "ZSZ";
				case "NW":
					return "SZ";
				case "NNW":
					return "SSZ";
				default: 
					return "";
			}
		}
	}
}
