using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SolutionErp.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class ExpandSupplierFields : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "AuthorizationNote",
                table: "Suppliers",
                type: "nvarchar(1000)",
                maxLength: 1000,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "BankAccount",
                table: "Suppliers",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ContactPhone",
                table: "Suppliers",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ContactTitle",
                table: "Suppliers",
                type: "nvarchar(150)",
                maxLength: 150,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Fax",
                table: "Suppliers",
                type: "nvarchar(50)",
                maxLength: 50,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "LegalRepTitle",
                table: "Suppliers",
                type: "nvarchar(150)",
                maxLength: 150,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "LegalRepresentative",
                table: "Suppliers",
                type: "nvarchar(200)",
                maxLength: 200,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "LinkGpkd",
                table: "Suppliers",
                type: "nvarchar(1000)",
                maxLength: 1000,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "LinkGuq",
                table: "Suppliers",
                type: "nvarchar(1000)",
                maxLength: 1000,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "LinkHsnl",
                table: "Suppliers",
                type: "nvarchar(1000)",
                maxLength: 1000,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MailRecipient",
                table: "Suppliers",
                type: "nvarchar(200)",
                maxLength: 200,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MailingAddress",
                table: "Suppliers",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "OfficeAddress",
                table: "Suppliers",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "OwnerPmh",
                table: "Suppliers",
                type: "nvarchar(150)",
                maxLength: 150,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "PackageCategory",
                table: "Suppliers",
                type: "nvarchar(300)",
                maxLength: 300,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "ReferralSource",
                table: "Suppliers",
                type: "nvarchar(300)",
                maxLength: 300,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "SecondaryBankAccount",
                table: "Suppliers",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "Status",
                table: "Suppliers",
                type: "int",
                nullable: true);

            // One-time un-cram: clear the legacy concatenated Note on the 4 seeded suppliers now that
            // their data lives in structured columns. Guarded exact-match prefix (Note LIKE N'Loại:%')
            // so manually-edited Notes are never touched (spec §4; safe on existing prod rows only).
            migrationBuilder.Sql(
                "UPDATE Suppliers SET Note = NULL " +
                "WHERE Code IN (N'TRUONGGIANG', N'TANPHU', N'TGN', N'DONGDUONG') " +
                "AND Note LIKE N'Loại:%';");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "AuthorizationNote",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "BankAccount",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "ContactPhone",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "ContactTitle",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "Fax",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "LegalRepTitle",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "LegalRepresentative",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "LinkGpkd",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "LinkGuq",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "LinkHsnl",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "MailRecipient",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "MailingAddress",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "OfficeAddress",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "OwnerPmh",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "PackageCategory",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "ReferralSource",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "SecondaryBankAccount",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "Status",
                table: "Suppliers");
        }
    }
}
