import { MigrationInterface, QueryRunner } from "typeorm";

/**
 * Accrual alert acknowledgements: ops can mark an in-warehouse item's fee
 * accrual as reviewed (optionally snoozed until a date) so it stops nudging and
 * drops down the accrual dashboard. One row per inventory item.
 */
export class CreateAccrualAcks2140000000000 implements MigrationInterface {
  name = "CreateAccrualAcks2140000000000";

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS freight.warehouse_accrual_acks (
        id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
        inventory_id uuid NOT NULL UNIQUE,
        acknowledged_by uuid,
        acknowledged_at timestamptz NOT NULL DEFAULT now(),
        snooze_until timestamptz,
        note text,
        created_at timestamptz NOT NULL DEFAULT now(),
        updated_at timestamptz NOT NULL DEFAULT now()
      )
    `);
  }

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