using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace NexusIdentity.Api.Migrations;

[Migration("20260605140000_RemoteFoundation")]
public partial class RemoteFoundation : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "DevicePresence",
            columns: table => new
            {
                DeviceId = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
                Online = table.Column<bool>(type: "INTEGER", nullable: false),
                HealthStatus = table.Column<int>(type: "INTEGER", nullable: false),
                LastSeenUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
                LastHeartbeatUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
                UserName = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
                OrganizationName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
                AgentVersion = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
                ShellVersion = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
                UpdatedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_DevicePresence", x => x.DeviceId);
                table.ForeignKey(
                    name: "FK_DevicePresence_Devices_DeviceId",
                    column: x => x.DeviceId,
                    principalTable: "Devices",
                    principalColumn: "DeviceId",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateTable(
            name: "DeviceHeartbeats",
            columns: table => new
            {
                Id = table.Column<Guid>(type: "TEXT", nullable: false),
                DeviceId = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
                ReceivedAtUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
                Online = table.Column<bool>(type: "INTEGER", nullable: false),
                HealthStatus = table.Column<int>(type: "INTEGER", nullable: false),
                UserName = table.Column<string>(type: "TEXT", maxLength: 128, nullable: false),
                OrganizationName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
                AgentVersion = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
                ShellVersion = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_DeviceHeartbeats", x => x.Id);
                table.ForeignKey(
                    name: "FK_DeviceHeartbeats_Devices_DeviceId",
                    column: x => x.DeviceId,
                    principalTable: "Devices",
                    principalColumn: "DeviceId",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateIndex(name: "IX_DeviceHeartbeats_DeviceId", table: "DeviceHeartbeats", column: "DeviceId");
        migrationBuilder.CreateIndex(name: "IX_DeviceHeartbeats_ReceivedAtUtc", table: "DeviceHeartbeats", column: "ReceivedAtUtc");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(name: "DeviceHeartbeats");
        migrationBuilder.DropTable(name: "DevicePresence");
    }
}
