using Backend.Data;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backend.Migrations;

[DbContext(typeof(AwardsDbContext))]
[Migration("20260629142746_EnsureDemoSeedSchema")]
public partial class EnsureDemoSeedSchema : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.Sql(
            """
            ALTER TABLE "Seasons" ADD COLUMN IF NOT EXISTS "IsDemo" boolean NOT NULL DEFAULT FALSE;
            ALTER TABLE "Seasons" ADD COLUMN IF NOT EXISTS "ShowStartsAt" time without time zone NOT NULL DEFAULT TIME '20:00';
            ALTER TABLE "Seasons" ADD COLUMN IF NOT EXISTS "WinnersPublishedAt" timestamp with time zone;
            ALTER TABLE "Seasons" ADD COLUMN IF NOT EXISTS "WinnersPublishedByTwitchId" character varying(120);
            ALTER TABLE "Seasons" ADD COLUMN IF NOT EXISTS "SubcategoryTemplatesJson" text NOT NULL DEFAULT '[]';
            ALTER TABLE "Seasons" ADD COLUMN IF NOT EXISTS "WorkflowRulesJson" text NOT NULL DEFAULT '[]';

            ALTER TABLE "Categories" ADD COLUMN IF NOT EXISTS "ViewerRangeMin" integer;
            ALTER TABLE "Categories" ADD COLUMN IF NOT EXISTS "ViewerRangeMax" integer;

            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "StreamerIdentityId" integer;
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "NominationTally" integer NOT NULL DEFAULT 0;
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "AcceptanceStatus" character varying(30) NOT NULL DEFAULT 'open';
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "AcceptanceNote" character varying(500);
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "ClipCompilationUrl" character varying(500);
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "ClipCompilationTitle" character varying(200);
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "ClipCompilationPlatform" character varying(40);
            ALTER TABLE "Candidates" ADD COLUMN IF NOT EXISTS "ClipEmbedStatus" character varying(30) NOT NULL DEFAULT 'unchecked';

            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "CategoryGroupName" character varying(80) NOT NULL DEFAULT '';
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "StreamerIdentityId" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "SuggestedCategoryId" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "ResolvedChannel" character varying(120);
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "ResolvedPlatform" character varying(40);
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "AvgViewers" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "HoursStreamed" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "HoursWatched" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "PeakViewers" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "FollowersGained" integer;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackerStatus" character varying(40) NOT NULL DEFAULT 'pending';
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackerCheckedAt" timestamp with time zone;
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackingReviewStatus" character varying(30) NOT NULL DEFAULT 'clear';
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackingFlagsJson" text NOT NULL DEFAULT '[]';
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackingReviewNote" character varying(1000);
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackingReviewedByTwitchId" character varying(120);
            ALTER TABLE "Nominations" ADD COLUMN IF NOT EXISTS "TrackingReviewedAt" timestamp with time zone;

            DO $vtsa_optional_demo_seed_schema$
            BEGIN
                IF to_regclass('"ClipSubmissions"') IS NOT NULL THEN
                    ALTER TABLE "ClipSubmissions" ADD COLUMN IF NOT EXISTS "CategoryId" integer;
                    ALTER TABLE "ClipSubmissions" ADD COLUMN IF NOT EXISTS "CandidateId" integer;
                END IF;

                IF to_regclass('"ShowactApplications"') IS NOT NULL THEN
                    ALTER TABLE "ShowactApplications" ADD COLUMN IF NOT EXISTS "FieldResponsesJson" text NOT NULL DEFAULT '{}';
                END IF;
            END;
            $vtsa_optional_demo_seed_schema$;
            """
        );
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}
