/** Permit lifecycle statuses (FK target ptw_permit_status.permit_status_id). */
export const PERMIT_STATUS = { DRAFT: 1, ACTIVE: 2, CLOSED: 3 };

const PERMIT_STATUS_SEED = [
  [PERMIT_STATUS.DRAFT, "Draft"],
  [PERMIT_STATUS.ACTIVE, "Active"],
  [PERMIT_STATUS.CLOSED, "Closed"]
];

/**
 * Idempotently ensure the default permit statuses exist so that writing
 * ptw_permits.permit_status_id never trips the foreign key. Safe to call on a
 * pool or a transaction connection; uses INSERT IGNORE so existing rows are
 * left untouched.
 */
export async function ensurePermitStatuses(db) {
  await db.query(
    `INSERT IGNORE INTO ptw_permit_status (permit_status_id, permit_status_name)
     VALUES (?, ?), (?, ?), (?, ?)`,
    PERMIT_STATUS_SEED.flat()
  );
}
