import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * Company stamp (seal) attached alongside the drawn signature, for both the
 * client and the EDR side. Stored the same way the signature image is: a
 * FileRecord on the contract (`resource: 'contracts'`, `code: 'stamp_<role>'`)
 * referenced from the signature row.
 *
 * Nullable — existing signature rows predate the stamp requirement. The
 * "both stamps recorded" gate lives in ContractTransitionService.counterSign,
 * not in a NOT NULL constraint, so historical rows stay readable.
 */
export class AddContractSignatureStamp2910000000000 implements MigrationInterface {
  name = 'AddContractSignatureStamp2910000000000';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.contract_signatures ADD COLUMN IF NOT EXISTS stamp_file_id uuid;`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE freight.contract_signatures DROP COLUMN IF EXISTS stamp_file_id;`,
    );
  }
}
