using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Knot.Modules.Auth.Migrations
{
    /// <inheritdoc />
    public partial class AddUserInfoFields : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(@"
                DO $$ 
                BEGIN 
                    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='identity' AND table_name='Users' AND column_name='BannedUntil') THEN
                        ALTER TABLE identity.""Users"" ADD ""BannedUntil"" timestamp with time zone;
                    END IF;

                    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='identity' AND table_name='Users' AND column_name='PhoneNumber') THEN
                        ALTER TABLE identity.""Users"" ADD ""PhoneNumber"" text;
                    END IF;

                    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema='identity' AND table_name='Users' AND column_name='RefreshToken') THEN
                        ALTER TABLE identity.""Users"" ADD ""RefreshToken"" text;
                    END IF;
                END $$;");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(name: "BannedUntil", schema: "identity", table: "Users");
            migrationBuilder.DropColumn(name: "PhoneNumber", schema: "identity", table: "Users");
            migrationBuilder.DropColumn(name: "RefreshToken", schema: "identity", table: "Users");
        }
    }
}
