import { MigrationInterface, QueryRunner } from "typeorm"

export class AddEntityForClientContract1755866480517 implements MigrationInterface {
  name = "AddEntityForClientContract1755866480517"

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `CREATE TABLE "client_company_contracts" ("id" SERIAL NOT NULL, "start_date" date NOT NULL, "end_date" date NOT NULL, "payment_plan_id" integer NOT NULL, "authorized_contact_id" integer NOT NULL, "description" text, "payment_schedule" character varying, "contract_document" character varying, "terms_and_conditions" text, "created_at" TIMESTAMP NOT NULL DEFAULT NOW(), "updated_at" TIMESTAMP NOT NULL DEFAULT NOW(), "deleted_at" TIMESTAMP, CONSTRAINT "PK_a1f22e7f4adfeadbb649ef39f1c" PRIMARY KEY ("id"))`,
    )
    await queryRunner.query(
      `ALTER TABLE "client_company_contracts" ADD CONSTRAINT "FK_45a8d04dac8513da1ae714bc348" FOREIGN KEY ("payment_plan_id") REFERENCES "pricing_plans"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
    await queryRunner.query(
      `ALTER TABLE "client_company_contracts" ADD CONSTRAINT "FK_3b269fbc9db6f53543a476e7af4" FOREIGN KEY ("authorized_contact_id") REFERENCES "client_company_contacts"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
    )
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE "client_company_contracts" DROP CONSTRAINT "FK_3b269fbc9db6f53543a476e7af4"`,
    )
    await queryRunner.query(
      `ALTER TABLE "client_company_contracts" DROP CONSTRAINT "FK_45a8d04dac8513da1ae714bc348"`,
    )
    await queryRunner.query(`DROP TABLE "client_company_contracts"`)
  }
}
