using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CvSearch.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddHeadlessBrowserToProviders : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<bool>(
                name: "UseHeadlessBrowser",
                schema: MigrationConstants.SchemaName,
                table: "JobProviders",
                type: "bit",
                nullable: false,
                defaultValue: false);

            // ejobs.ro (Id=1) is a Nuxt SPA — the old /user/ URL 404s and plain HTTP GET
            // returns only the JS bundle, not actual job listings.
            // Fix: use the correct search URL and headless Chromium to render job results.
            migrationBuilder.UpdateData(
                schema: MigrationConstants.SchemaName,
                table: "JobProviders",
                keyColumn: "Id",
                keyValue: 1,
                columns: ["SearchUrlTemplate", "JobLinkContains", "UseHeadlessBrowser"],
                values: new object[] { "https://www.ejobs.ro/locuri-de-munca?q={keywords}", "/locuri-de-munca/", true });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.UpdateData(
                schema: MigrationConstants.SchemaName,
                table: "JobProviders",
                keyColumn: "Id",
                keyValue: 1,
                columns: ["SearchUrlTemplate", "JobLinkContains", "UseHeadlessBrowser"],
                values: new object[] { "https://www.ejobs.ro/user/locuri-de-munca/?utm_source=myai&q={keywords}", "/user/locuri-de-munca/", false });

            migrationBuilder.DropColumn(
                name: "UseHeadlessBrowser",
                schema: MigrationConstants.SchemaName,
                table: "JobProviders");
        }
    }
}
