-- Wave 9: Parties (Internal Reference - Suppliers/Customers linked entities)
CREATE TABLE IF NOT EXISTS parties (
  id TEXT PRIMARY KEY,
  party_type TEXT NOT NULL,
  entity_id TEXT NOT NULL,
  party_name TEXT NOT NULL,
  party_code TEXT,
  contact_info TEXT,
  address TEXT,
  notes TEXT,
  raw JSONB NOT NULL DEFAULT '{}'::jsonb,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_parties_type ON parties (party_type);
CREATE INDEX IF NOT EXISTS idx_parties_entity_id ON parties (entity_id);
CREATE INDEX IF NOT EXISTS idx_parties_code ON parties (party_code);
