using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CvSearch.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddJobProviders : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "JobProviders",
                schema: MigrationConstants.SchemaName,
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    Enabled = table.Column<bool>(type: "bit", nullable: false),
                    SearchUrlTemplate = table.Column<string>(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
                    JobLinkContains = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    InitialKeywordsJson = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false, defaultValue: "[]"),
                    MaxResults = table.Column<int>(type: "int", nullable: false, defaultValue: 20),
                    DisplayOrder = table.Column<int>(type: "int", nullable: false, defaultValue: 0)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_JobProviders", x => x.Id);
                });

            // Seed the three default providers — all disabled so the feature is opt-in per environment.
            // Enable a provider by setting its Enabled column to 1 via SQL or a future admin UI.
            migrationBuilder.InsertData(
                schema: MigrationConstants.SchemaName,
                table: "JobProviders",
                columns: ["Name", "Enabled", "SearchUrlTemplate", "JobLinkContains", "InitialKeywordsJson", "MaxResults", "DisplayOrder"],
                values: new object[,]
                {
                    { "ejobs.ro",     false, "https://www.ejobs.ro/user/locuri-de-munca/?utm_source=myai&q={keywords}", "/user/locuri-de-munca/",      "[]", 20, 0 },
                    { "bestjobs.eu",  false, "https://www.bestjobs.eu/ro/locuri-de-munca?keywords={keywords}",           "/ro/locuri-de-munca/",         "[]", 20, 1 },
                    { "linkedin.com", false, "https://www.linkedin.com/jobs/search/?keywords={keywords}",                "/jobs/view/",                  "[]", 20, 2 },
                });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "JobProviders",
                schema: MigrationConstants.SchemaName);
        }
    }
}
