using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backend.Migrations
{
    /// <inheritdoc />
    public partial class SeedExampleSponsorsForCurrentSeason : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(
                """
                WITH target_season AS (
                    SELECT "Id"
                    FROM "Seasons"
                    WHERE "IsCurrent" = TRUE
                    ORDER BY "Year" DESC, "Id" DESC
                    LIMIT 1
                )
                INSERT INTO "Sponsors" (
                    "SeasonId", "Name", "WebsiteUrl", "LogoUrl", "Description", "Tier", "SortOrder", "IsVisible", "CreatedAt", "UpdatedAt"
                )
                SELECT
                    target_season."Id",
                    seed."Name",
                    seed."WebsiteUrl",
                    seed."LogoUrl",
                    seed."Description",
                    seed."Tier",
                    seed."SortOrder",
                    TRUE,
                    TIMESTAMPTZ '2026-06-29 19:22:20+00',
                    NULL::timestamptz
                FROM target_season
                CROSS JOIN (
                    VALUES
                        ('HoshiForge Studio', 'https://example.invalid/hoshiforge', '/demo/sponsors/hoshiforge-studio.svg', 'Branding-, Overlay- und Debuet-Visuals fuer VTuber-Projekte und Community-Events.', 'Presenting Sponsor', 10),
                        ('NekoPixel Energy', 'https://example.invalid/nekopixel', '/demo/sponsors/nekopixel-energy.svg', 'Community-fokussierter Drink-Partner fuer lange Showabende, Watchpartys und Creator-Collabs.', 'Gold Partner', 20),
                        ('PrismLoop Audio', 'https://example.invalid/prismloop', '/demo/sponsors/prismloop-audio.svg', 'Audio-Tools, Intro-Packs und Stream-Sounddesign fuer Live-Shows und Highlight-Clips.', 'Gold Partner', 30),
                        ('CloudBeacon Hosting', 'https://example.invalid/cloudbeacon', '/demo/sponsors/cloudbeacon-hosting.svg', 'Skalierbares Hosting fuer Voting, Landingpages und Event-Traffic rund um Showtage.', 'Tech Partner', 40),
                        ('ChibiCanvas Market', 'https://example.invalid/chibicanvas', '/demo/sponsors/chibicanvas-market.svg', 'Merch-, Sticker- und Artist-Marketplace mit Fokus auf VTuber, Emotes und Fanartikel.', 'Community Partner', 50)
                ) AS seed("Name", "WebsiteUrl", "LogoUrl", "Description", "Tier", "SortOrder")
                WHERE NOT EXISTS (
                    SELECT 1
                    FROM "Sponsors" existing
                    WHERE existing."SeasonId" = target_season."Id"
                );
                """
            );
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(
                """
                DELETE FROM "Sponsors"
                WHERE "Name" IN (
                    'HoshiForge Studio',
                    'NekoPixel Energy',
                    'PrismLoop Audio',
                    'CloudBeacon Hosting',
                    'ChibiCanvas Market'
                );
                """
            );
        }
    }
}
