-- Staging table for the Buildium payee/payor register backfill.
-- Maps a Buildium GL transaction id to the resolved local vendor/customer and
-- the party name, so the materialized bank register (accounting.transactions)
-- of imported-GL companies can be backfilled by bridging transaction → journal
-- entry (by bank line) → this map. Populated by the buildium-payee-backfill
-- edge function ("partymap" mode).
create table if not exists accounting.buildium_party_map (
  company_id uuid not null,
  external_id text not null,
  party_name text,
  vendor_id uuid,
  customer_id uuid,
  party_type text,
  updated_at timestamptz not null default now(),
  primary key (company_id, external_id)
);

comment on table accounting.buildium_party_map is
  'Staging: Buildium GL transaction id -> resolved local vendor/customer + name, used to backfill the materialized bank register (accounting.transactions) for imported companies.';
