using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace VigilCareClinicalAPI.Migrations
{
    /// <inheritdoc />
    public partial class AddPhiAccessLogs : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "phi_access_logs",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
                    access_type = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    patient_id = table.Column<Guid>(type: "uuid", nullable: true),
                    user_id = table.Column<Guid>(type: "uuid", nullable: false),
                    user_display_name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    resource_path = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    search_query_hash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    result_count = table.Column<int>(type: "integer", nullable: true),
                    ip_address = table.Column<string>(type: "character varying(45)", maxLength: 45, nullable: true),
                    correlation_id = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
                    accessed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "NOW()")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_phi_access_logs", x => x.id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_phi_access_logs_accessed_at",
                table: "phi_access_logs",
                column: "accessed_at");

            migrationBuilder.CreateIndex(
                name: "IX_phi_access_logs_patient_id",
                table: "phi_access_logs",
                column: "patient_id");

            migrationBuilder.CreateIndex(
                name: "IX_phi_access_logs_user_id",
                table: "phi_access_logs",
                column: "user_id");
        }

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