using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backend.Migrations
{
    /// <inheritdoc />
    public partial class SanitizeDemoCategoryDescriptions : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(
                """
                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)
        {
            migrationBuilder.Sql(
                """
                UPDATE "Categories"
                SET "Description" = "Description" || ' Demo-Tier: ' || "Name" || '.'
                WHERE "ViewerRangeMin" IS NOT NULL
                  AND "Description" NOT LIKE '%Demo-Tier:%';

                UPDATE "Categories"
                SET "Description" = replace("Description", 'aktuellen Season', 'aktuellen Demo-Season')
                WHERE "Slug" LIKE 'main-awards-%'
                  AND "Description" LIKE '%aktuellen Season%';
                """
            );
        }
    }
}
