using System;
using Microsoft.EntityFrameworkCore.Migrations;
using MySql.EntityFrameworkCore.Metadata;

namespace MeteoWebApp.Migrations
{
    public partial class Initial : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Stations",
                columns: table => new
                {
                    StationId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true),
                    GpsLatitude = table.Column<float>(type: "float", nullable: false),
                    GpsLongitude = table.Column<float>(type: "float", nullable: false),
                    ApiKey = table.Column<byte[]>(type: "varbinary(16)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Stations", x => x.StationId);
                });

            migrationBuilder.CreateTable(
                name: "Measurements",
                columns: table => new
                {
                    MeasurementId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    StationId = table.Column<int>(type: "int", nullable: false),
                    Timestamp = table.Column<DateTime>(type: "datetime", nullable: false),
                    Temperature = table.Column<float>(type: "float", nullable: false),
                    DewPoint = table.Column<float>(type: "float", nullable: false),
                    TemperatureFeelsLike = table.Column<float>(type: "float", nullable: false),
                    Humidity = table.Column<float>(type: "float", nullable: false),
                    Pressure = table.Column<float>(type: "float", nullable: false),
                    SeaLevelPressure = table.Column<float>(type: "float", nullable: false),
                    WindSpeed = table.Column<float>(type: "float", nullable: false),
                    WindAngle = table.Column<float>(type: "float", nullable: false),
                    WindAngleStr = table.Column<string>(type: "varchar(3)", maxLength: 3, nullable: true),
                    RainAmmount = table.Column<float>(type: "float", nullable: false),
                    UvIndex = table.Column<float>(type: "float", nullable: false),
                    SoilTempDepth1 = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true),
                    SoilTemp1 = table.Column<float>(type: "float", nullable: false),
                    SoilTempDepth2 = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true),
                    SoilTemp2 = table.Column<float>(type: "float", nullable: false),
                    SoilTempDepth3 = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true),
                    SoilTemp3 = table.Column<float>(type: "float", nullable: false),
                    SoilMoistureDepth1 = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true),
                    SoilMoisture1 = table.Column<float>(type: "float", nullable: false),
                    SoilMoistureDepth2 = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true),
                    SoilMoisture2 = table.Column<float>(type: "float", nullable: false),
                    SoilMoistureDepth3 = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true),
                    SoilMoisture3 = table.Column<float>(type: "float", nullable: false),
                    BatteryVoltage = table.Column<float>(type: "float", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Measurements", x => x.MeasurementId);
                    table.ForeignKey(
                        name: "FK_Measurements_Stations_StationId",
                        column: x => x.StationId,
                        principalTable: "Stations",
                        principalColumn: "StationId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Measurements_StationId",
                table: "Measurements",
                column: "StationId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Measurements");

            migrationBuilder.DropTable(
                name: "Stations");
        }
    }
}
