using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace JobTrackerApi.Migrations
{
    /// <inheritdoc />
    public partial class AddCompanyCrmAndChecklistAndIndexes : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "RecruiterName",
                table: "Companies",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "RecruiterEmail",
                table: "Companies",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "RecruiterLinkedIn",
                table: "Companies",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "LastContactedAt",
                table: "Companies",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "NextContactAt",
                table: "Companies",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "PipelineStage",
                table: "Companies",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "HasResume",
                table: "JobApplications",
                type: "INTEGER",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "HasCoverLetter",
                table: "JobApplications",
                type: "INTEGER",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "HasPortfolio",
                table: "JobApplications",
                type: "INTEGER",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "HasOtherAttachment",
                table: "JobApplications",
                type: "INTEGER",
                nullable: false,
                defaultValue: false);

            // Indexes for common queries
            migrationBuilder.Sql("CREATE INDEX IF NOT EXISTS IX_JobApplications_DateApplied ON JobApplications(DateApplied);");
            migrationBuilder.Sql("CREATE INDEX IF NOT EXISTS IX_JobApplications_Status ON JobApplications(Status);");
            migrationBuilder.Sql("CREATE INDEX IF NOT EXISTS IX_Companies_Name ON Companies(Name);");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql("DROP INDEX IF EXISTS IX_JobApplications_DateApplied;");
            migrationBuilder.Sql("DROP INDEX IF EXISTS IX_JobApplications_Status;");
            migrationBuilder.Sql("DROP INDEX IF EXISTS IX_Companies_Name;");

            migrationBuilder.DropColumn(name: "RecruiterName", table: "Companies");
            migrationBuilder.DropColumn(name: "RecruiterEmail", table: "Companies");
            migrationBuilder.DropColumn(name: "RecruiterLinkedIn", table: "Companies");
            migrationBuilder.DropColumn(name: "LastContactedAt", table: "Companies");
            migrationBuilder.DropColumn(name: "NextContactAt", table: "Companies");
            migrationBuilder.DropColumn(name: "PipelineStage", table: "Companies");

            migrationBuilder.DropColumn(name: "HasResume", table: "JobApplications");
            migrationBuilder.DropColumn(name: "HasCoverLetter", table: "JobApplications");
            migrationBuilder.DropColumn(name: "HasPortfolio", table: "JobApplications");
            migrationBuilder.DropColumn(name: "HasOtherAttachment", table: "JobApplications");
        }
    }
}

