using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace OmsorgCore.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddTravelCostModeAndEmployeeFacilityDistances : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "TravelCostMode",
                table: "facilities",
                type: "character varying(20)",
                maxLength: 20,
                nullable: false,
                defaultValue: "Pauschale");

            migrationBuilder.AddColumn<decimal>(
                name: "TravelCostPerKm",
                table: "facilities",
                type: "numeric(10,2)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "employee_facility_distances",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    FacilityId = table.Column<Guid>(type: "uuid", nullable: false),
                    EmployeeId = table.Column<Guid>(type: "uuid", nullable: false),
                    DistanceKm = table.Column<decimal>(type: "numeric(10,2)", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_employee_facility_distances", x => x.Id);
                    table.ForeignKey(
                        name: "FK_employee_facility_distances_employees_EmployeeId",
                        column: x => x.EmployeeId,
                        principalTable: "employees",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_employee_facility_distances_facilities_FacilityId",
                        column: x => x.FacilityId,
                        principalTable: "facilities",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_employee_facility_distances_EmployeeId",
                table: "employee_facility_distances",
                column: "EmployeeId");

            migrationBuilder.CreateIndex(
                name: "IX_employee_facility_distances_FacilityId",
                table: "employee_facility_distances",
                column: "FacilityId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "employee_facility_distances");

            migrationBuilder.DropColumn(
                name: "TravelCostMode",
                table: "facilities");

            migrationBuilder.DropColumn(
                name: "TravelCostPerKm",
                table: "facilities");
        }
    }
}
