using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backend.Migrations
{
    /// <inheritdoc />
    public partial class RefreshLiveDemoPublicContent : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(
                """
                UPDATE "SiteSettings"
                SET
                    "ShareXUrl" = CASE
                        WHEN COALESCE(NULLIF("ShareXUrl", ''), '') IN ('', 'https://x.com/intent/tweet', 'https://x.com/jayuhime')
                            THEN 'https://x.com/intent/tweet?text=Schaut%20euch%20die%20VTuber%20Star%20Awards%20an!&url=https%3A%2F%2Faward.noveria.net'
                        ELSE "ShareXUrl"
                    END,
                    "ShareDiscordUrl" = CASE
                        WHEN COALESCE(NULLIF("ShareDiscordUrl", ''), '') IN ('', 'https://discord.gg/')
                            THEN 'https://discord.gg/jayuhime'
                        ELSE "ShareDiscordUrl"
                    END
                WHERE "Id" = 1;

                UPDATE "Categories"
                SET "Description" = trim(
                    regexp_replace(
                        replace("Description", 'aktuellen Demo-Season', 'aktuellen Season'),
                        '\s*Demo-Tier:\s*[^.]+\.',
                        '',
                        'g'
                    )
                )
                WHERE "Description" LIKE '%Demo-Tier:%'
                   OR "Description" LIKE '%aktuellen Demo-Season%';
                """
            );
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {

        }
    }
}
