-- ======================
-- MESSAGING: Channel
-- ======================
CREATE FOREIGN TABLE unified_messaging_channels (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  parent_channel_id    text,
  parent_id            text,
  has_subchannels      boolean,
  members              jsonb,
  is_active            boolean,
  is_private           boolean,
  web_url              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/messaging/{connection_id}/channel');

-- ======================
-- MESSAGING: Message
-- ======================
CREATE FOREIGN TABLE unified_messaging_messages (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  channel_id           text,
  channel_ids          text[],
  channels             jsonb,
  parent_id            text,
  parent_message_id    text,
  root_message_id      text,
  message_thread_identifier text,
  author_member        jsonb,
  destination_members  jsonb,
  hidden_members       jsonb,
  mentioned_members    jsonb,
  reactions            jsonb,
  subject              text,
  message              text,
  message_html         text,
  message_markdown     text,
  attachments          jsonb,
  web_url              text,
  reference            text,
  has_children         boolean,
  is_unread            boolean,
  buttons              jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/messaging/{connection_id}/message');

-- ======================
-- CRM: Deal
-- ======================
CREATE FOREIGN TABLE unified_crm_deals (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  amount               numeric,
  currency             text,
  closed_at            timestamptz,
  stage                text,
  stage_id             text,
  pipeline             text,
  pipeline_id          text,
  source               text,
  probability          numeric,
  tags                 text[],
  lost_reason          text,
  won_reason           text,
  user_id              text,
  contact_ids          text[],
  company_ids          text[],
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/crm/{connection_id}/deal');

-- ======================
-- CRM: Contact
-- ======================
CREATE FOREIGN TABLE unified_crm_contacts (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  title                text,
  company              text,
  emails               jsonb,
  telephones           jsonb,
  deal_ids             text[],
  company_ids          text[],
  address              jsonb,
  user_id              text,
  link_urls            text[],
  metadata             jsonb,
  department           text,
  image_url            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/crm/{connection_id}/contact');

-- ======================
-- CRM: Company
-- ======================
CREATE FOREIGN TABLE unified_crm_companies (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  deal_ids             text[],
  contact_ids          text[],
  emails               jsonb,
  telephones           jsonb,
  websites             text[],
  address              jsonb,
  is_active            boolean,
  tags                 text[],
  description          text,
  industry             text,
  link_urls            text[],
  employees            numeric,
  timezone             text,
  user_id              text,
  metadata             jsonb,
  domains              text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/crm/{connection_id}/company');

-- ======================
-- CRM: Event
-- ======================
CREATE FOREIGN TABLE unified_crm_events (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  type                 text,
  note                 jsonb,
  meeting              jsonb,
  email                jsonb,
  call                 jsonb,
  task                 jsonb,
  marketing_email      jsonb,
  form                 jsonb,
  page_view            jsonb,
  deal_ids             text[],
  company_ids          text[],
  contact_ids          text[],
  lead_ids             text[],
  user_id              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/crm/{connection_id}/event');

-- ======================
-- CRM: Lead
-- ======================
CREATE FOREIGN TABLE unified_crm_leads (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  user_id              text,
  creator_user_id      text,
  contact_id           text,
  company_id           text,
  company_name         text,
  is_active            boolean,
  address              jsonb,
  emails               jsonb,
  telephones           jsonb,
  source               text,
  status               text,
  link_urls            text[],
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/crm/{connection_id}/lead');

-- ======================
-- CRM: Pipeline
-- ======================
CREATE FOREIGN TABLE unified_crm_pipelines (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  is_active            boolean,
  deal_probability     numeric,
  display_order        numeric,
  stages               jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/crm/{connection_id}/pipeline');

-- ======================
-- MARTECH: List
-- ======================
CREATE FOREIGN TABLE unified_martech_lists (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  start_at             timestamptz,
  end_at               timestamptz,
  user_id              text,
  is_active            boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/martech/{connection_id}/list');

-- ======================
-- MARTECH: Member
-- ======================
CREATE FOREIGN TABLE unified_martech_members (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  emails               jsonb,
  list_ids             text[],
  tags                 text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/martech/{connection_id}/member');

-- ======================
-- TICKETING: Ticket
-- ======================
CREATE FOREIGN TABLE unified_ticketing_tickets (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  customer_id          text,
  subject              text,
  description          text,
  status               text,
  closed_at            timestamptz,
  priority             text,
  category_id          text,
  category             text,
  source               text,
  source_ref           text,
  tags                 text[],
  user_id              text,
  url                  text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ticketing/{connection_id}/ticket');

-- ======================
-- TICKETING: Customer
-- ======================
CREATE FOREIGN TABLE unified_ticketing_customers (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  emails               jsonb,
  telephones           jsonb,
  tags                 text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ticketing/{connection_id}/customer');

-- ======================
-- TICKETING: Note
-- ======================
CREATE FOREIGN TABLE unified_ticketing_notes (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  customer_id          text,
  description          text,
  ticket_id            text,
  user_id              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ticketing/{connection_id}/note');

-- ======================
-- TICKETING: Category
-- ======================
CREATE FOREIGN TABLE unified_ticketing_categories (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  is_active            boolean,
  parent_id            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ticketing/{connection_id}/category');

-- ======================
-- UC: Call
-- ======================
CREATE FOREIGN TABLE unified_uc_calls (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  contact_id           text,
  telephone            jsonb,
  start_at             timestamptz,
  end_at               timestamptz,
  user_id              text,
  contacts             jsonb,
  is_private           boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/uc/{connection_id}/call');

-- ======================
-- UC: Contact
-- ======================
CREATE FOREIGN TABLE unified_uc_contacts (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  title                text,
  company              text,
  emails               jsonb,
  telephones           jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/uc/{connection_id}/contact');

-- ======================
-- UC: Comment
-- ======================
CREATE FOREIGN TABLE unified_uc_comments (
  connection_id        text NOT NULL,
  id                   text,
  created_at           text,
  updated_at           text,
  content              text,
  user_id              text,
  call_id              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/uc/{connection_id}/comment');

-- ======================
-- UC: Recording
-- ======================
CREATE FOREIGN TABLE unified_uc_recordings (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  start_at             timestamptz,
  end_at               timestamptz,
  expires_at           timestamptz,
  call_id              text,
  web_url              text,
  contact_id           text,
  contact_name         text,
  contact_phone        text,
  user_id              text,
  media                jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/uc/{connection_id}/recording');

-- ======================
-- ATS: Activity
-- ======================
CREATE FOREIGN TABLE unified_ats_activities (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  candidate_id         text,
  application_id       text,
  job_id               text,
  interview_id         text,
  document_id          text,
  title                text,
  description          text,
  is_private           boolean,
  user_ids             text[],
  type                 text,
  from                 jsonb,
  to                   jsonb,
  cc                   jsonb,
  bcc                  jsonb,
  sub_type             text,
  raw                  jsonb,
  document_ids         text[]
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/activity');

-- ======================
-- ATS: Candidate
-- ======================
CREATE FOREIGN TABLE unified_ats_candidates (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  emails               jsonb,
  title                text,
  telephones           jsonb,
  company_name         text,
  image_url            text,
  tags                 text[],
  address              jsonb,
  external_identifier  text,
  link_urls            text[],
  origin               text,
  company_id           text,
  sources              text[],
  date_of_birth        timestamptz,
  user_id              text,
  web_url              text,
  experiences          jsonb,
  education            jsonb,
  skills               text[],
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/candidate');

-- ======================
-- ATS: Job
-- ======================
CREATE FOREIGN TABLE unified_ats_jobs (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  recruiter_ids        text[],
  hiring_manager_ids   text[],
  status               text,
  closed_at            timestamptz,
  addresses            jsonb,
  compensation         jsonb,
  employment_type      text,
  remote               boolean,
  departments          text[],
  language_locale      text,
  public_job_urls      text[],
  number_of_openings   numeric,
  company_id           text,
  questions            jsonb,
  postings             jsonb,
  groups               jsonb,
  openings             jsonb,
  minimum_experience_years numeric,
  minimum_degree       text,
  skills               text[],
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/job');

-- ======================
-- ATS: Interview
-- ======================
CREATE FOREIGN TABLE unified_ats_interviews (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  candidate_id         text,
  job_id               text,
  application_id       text,
  user_ids             text[],
  status               text,
  start_at             timestamptz,
  end_at               timestamptz,
  location             text,
  external_event_xref  text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/interview');

-- ======================
-- ATS: Document
-- ======================
CREATE FOREIGN TABLE unified_ats_documents (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  document_url         text,
  document_data        text,
  filename             text,
  type                 text,
  candidate_id         text,
  application_id       text,
  job_id               text,
  user_id              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/document');

-- ======================
-- ATS: Applicationstatus
-- ======================
CREATE FOREIGN TABLE unified_ats_applicationstatuses (
  connection_id        text NOT NULL,
  id                   text,
  status               text,
  original_status      text,
  description          text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/applicationstatus');

-- ======================
-- ATS: Application
-- ======================
CREATE FOREIGN TABLE unified_ats_applications (
  connection_id        text NOT NULL,
  id                   text,
  candidate_id         text,
  job_id               text,
  created_at           timestamptz,
  updated_at           timestamptz,
  applied_at           timestamptz,
  hired_at             timestamptz,
  rejected_at          timestamptz,
  rejected_reason      text,
  source               text,
  status               text,
  original_status      text,
  answers              jsonb,
  offers               jsonb,
  user_id              text,
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/application');

-- ======================
-- ATS: Scorecard
-- ======================
CREATE FOREIGN TABLE unified_ats_scorecards (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  application_id       text,
  interviewer_id       text,
  interview_id         text,
  candidate_id         text,
  job_id               text,
  recommendation       text,
  comment              text,
  questions            jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/scorecard');

-- ======================
-- ATS: Company
-- ======================
CREATE FOREIGN TABLE unified_ats_companies (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  address              jsonb,
  website_url          text,
  phone                text,
  parent_id            text,
  recruiter_ids        text[],
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/ats/{connection_id}/company');

-- ======================
-- HRIS: Employee
-- ======================
CREATE FOREIGN TABLE unified_hris_employees (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  emails               jsonb,
  department           text,
  division             text,
  title                text,
  manager_id           text,
  employment_status    text,
  location             text,
  gender               text,
  telephones           jsonb,
  date_of_birth        timestamptz,
  employee_number      text,
  hired_at             timestamptz,
  terminated_at        timestamptz,
  marital_status       text,
  employment_type      text,
  address              jsonb,
  language_locale      text,
  currency             text,
  timezone             text,
  image_url            text,
  company_id           text,
  pronouns             text,
  employee_roles       text[],
  compensation         jsonb,
  salutation           text,
  bio                  text,
  ssn_sin              text,
  groups               jsonb,
  locations            jsonb,
  metadata             jsonb,
  storage_quota_allocated numeric,
  storage_quota_used   numeric,
  storage_quota_available numeric,
  relationships        jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/employee');

-- ======================
-- HRIS: Company
-- ======================
CREATE FOREIGN TABLE unified_hris_companies (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  legal_name           text,
  address              jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/company');

-- ======================
-- HRIS: Location
-- ======================
CREATE FOREIGN TABLE unified_hris_locations (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  address              jsonb,
  parent_id            text,
  external_identifier  text,
  telephones           jsonb,
  timezone             text,
  currency             text,
  language_locale      text,
  is_active            boolean,
  is_hq                boolean,
  raw                  jsonb,
  company_id           text
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/location');

-- ======================
-- HRIS: Group
-- ======================
CREATE FOREIGN TABLE unified_hris_groups (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  parent_id            text,
  type                 text,
  user_ids             text[],
  manager_ids          text[],
  is_active            boolean,
  company_id           text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/group');

-- ======================
-- HRIS: Timeoff
-- ======================
CREATE FOREIGN TABLE unified_hris_timeoffs (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  user_id              text,
  company_id           text,
  start_at             timestamptz,
  end_at               timestamptz,
  is_paid              boolean,
  status               text,
  approver_user_id     text,
  approved_at          timestamptz,
  comments             text,
  raw                  jsonb,
  reason               text
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/timeoff');

-- ======================
-- HRIS: Payslip
-- ======================
CREATE FOREIGN TABLE unified_hris_payslips (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  user_id              text,
  company_id           text,
  payment_type         text,
  paid_at              timestamptz,
  start_at             timestamptz,
  end_at               timestamptz,
  currency             text,
  gross_amount         numeric,
  net_amount           numeric,
  details              jsonb,
  raw                  jsonb,
  deduction            jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/payslip');

-- ======================
-- HRIS: Device
-- ======================
CREATE FOREIGN TABLE unified_hris_devices (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  asset_tag            text,
  version              text,
  manufacturer         text,
  model                text,
  os                   text,
  os_version           text,
  user_ids             text[],
  admin_user_ids       text[],
  location_id          text,
  has_antivirus        boolean,
  has_password_manager boolean,
  has_firewall         boolean,
  has_hd_encrypted     boolean,
  has_screenlock       boolean,
  is_missing           boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/device');

-- ======================
-- HRIS: Timeshift
-- ======================
CREATE FOREIGN TABLE unified_hris_timeshifts (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  employee_user_id     text,
  start_at             timestamptz,
  end_at               timestamptz,
  location_id          text,
  company_id           text,
  group_id             text,
  compensation         jsonb,
  approver_user_id     text,
  approved_at          timestamptz,
  hours                numeric,
  is_approved          boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/timeshift');

-- ======================
-- HRIS: Benefit
-- ======================
CREATE FOREIGN TABLE unified_hris_benefits (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  company_id           text,
  type                 text,
  tax                  text,
  frequency            text,
  is_active            boolean,
  employer_contribution_type text,
  employer_contribution_amount numeric,
  employer_contribution_max_amount numeric,
  coverage_level       text,
  currency             text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/benefit');

-- ======================
-- HRIS: Deduction
-- ======================
CREATE FOREIGN TABLE unified_hris_deductions (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  user_id              text,
  company_id           text,
  benefit_id           text,
  amount               numeric,
  type                 text,
  coverage_level       text,
  frequency            text,
  start_at             timestamptz,
  end_at               timestamptz,
  is_active            boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/hris/{connection_id}/deduction');

-- ======================
-- VERIFICATION: Package
-- ======================
CREATE FOREIGN TABLE unified_verification_packages (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  type                 text,
  aliases              text[],
  tags                 text[],
  description          text,
  parameters           jsonb,
  average_processing_times jsonb,
  has_redirect_url     boolean,
  has_target_url       boolean,
  needs_ip_address     boolean,
  cost_amount          numeric,
  currency             text,
  max_score            numeric,
  info_url             text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/verification/{connection_id}/package');

-- ======================
-- VERIFICATION: Request
-- ======================
CREATE FOREIGN TABLE unified_verification_requests (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  package_id           text,
  parameters           jsonb,
  target_url           text,
  candidate_id         text,
  profile_ip_address   text,
  profile_name         text,
  profile_date_of_birth text,
  profile_addresses    jsonb,
  profile_gender       text,
  profile_emails       text[],
  profile_telephones   text[],
  profile_national_identifier text,
  response_completed_at timestamptz,
  response_expires_at  timestamptz,
  response_issued_at   timestamptz,
  response_status      text,
  response_score       numeric,
  response_redirect_url text,
  response_download_urls text[],
  response_details     jsonb,
  response_source      text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/verification/{connection_id}/request');

-- ======================
-- ACCOUNTING: Account
-- ======================
CREATE FOREIGN TABLE unified_accounting_accounts (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  type                 text,
  status               text,
  balance              numeric,
  currency             text,
  customer_defined_code text,
  is_payable           boolean,
  parent_account_id    text,
  section              text,
  subsection           text,
  group                text,
  subgroup             text,
  parent_id            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/account');

-- ======================
-- ACCOUNTING: Journal
-- ======================
CREATE FOREIGN TABLE unified_accounting_journals (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  reference            text,
  tax_amount           numeric,
  currency             text,
  lineitems            jsonb,
  taxrate_id           text,
  description          text,
  posted_at            timestamptz,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/journal');

-- ======================
-- ACCOUNTING: Transaction
-- ======================
CREATE FOREIGN TABLE unified_accounting_transactions (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  memo                 text,
  total_amount         numeric,
  tax_amount           numeric,
  account_id           text,
  contact_id           text,
  reference            text,
  sub_total_amount     numeric,
  split_account_id     text,
  payment_method       text,
  payment_terms        text,
  customer_message     text,
  type                 text,
  lineitems            jsonb,
  currency             text,
  contacts             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/transaction');

-- ======================
-- ACCOUNTING: Contact
-- ======================
CREATE FOREIGN TABLE unified_accounting_contacts (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  emails               jsonb,
  telephones           jsonb,
  currency             text,
  billing_address      jsonb,
  shipping_address     jsonb,
  is_active            boolean,
  tax_exemption        text,
  tax_number           text,
  is_customer          boolean,
  is_supplier          boolean,
  portal_url           text,
  payment_methods      jsonb,
  company_name         text,
  identification       text,
  associated_contacts  jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/contact');

-- ======================
-- ACCOUNTING: Invoice
-- ======================
CREATE FOREIGN TABLE unified_accounting_invoices (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  due_at               timestamptz,
  paid_at              timestamptz,
  refunded_at          timestamptz,
  cancelled_at         timestamptz,
  posted_at            timestamptz,
  total_amount         numeric,
  paid_amount          numeric,
  refund_amount        numeric,
  tax_amount           numeric,
  discount_amount      numeric,
  balance_amount       numeric,
  invoice_number       text,
  reference            text,
  contact_id           text,
  currency             text,
  notes                text,
  refund_reason        text,
  lineitems            jsonb,
  status               text,
  url                  text,
  payment_collection_method text,
  invoice_at           timestamptz,
  type                 text,
  attachments          jsonb,
  send                 boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/invoice');

-- ======================
-- ACCOUNTING: Bill
-- ======================
CREATE FOREIGN TABLE unified_accounting_bills (
  connection_id        text NOT NULL,
  id                   text,
  bill_number          text,
  created_at           timestamptz,
  updated_at           timestamptz,
  due_at               timestamptz,
  paid_at              timestamptz,
  refunded_at          timestamptz,
  cancelled_at         timestamptz,
  posted_at            timestamptz,
  total_amount         numeric,
  paid_amount          numeric,
  refund_amount        numeric,
  tax_amount           numeric,
  discount_amount      numeric,
  balance_amount       numeric,
  contact_id           text,
  currency             text,
  notes                text,
  refund_reason        text,
  lineitems            jsonb,
  status               text,
  url                  text,
  payment_collection_method text,
  attachments          jsonb,
  send                 boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/bill');

-- ======================
-- ACCOUNTING: Creditmemo
-- ======================
CREATE FOREIGN TABLE unified_accounting_creditmemoes (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  due_at               timestamptz,
  paid_at              timestamptz,
  refunded_at          timestamptz,
  cancelled_at         timestamptz,
  posted_at            timestamptz,
  total_amount         numeric,
  paid_amount          numeric,
  refund_amount        numeric,
  tax_amount           numeric,
  discount_amount      numeric,
  balance_amount       numeric,
  creditmemo_number    text,
  contact_id           text,
  currency             text,
  notes                text,
  refund_reason        text,
  lineitems            jsonb,
  status               text,
  url                  text,
  payment_collection_method text,
  attachments          jsonb,
  send                 boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/creditmemo');

-- ======================
-- ACCOUNTING: Taxrate
-- ======================
CREATE FOREIGN TABLE unified_accounting_taxrates (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  rate                 numeric,
  is_active            boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/taxrate');

-- ======================
-- ACCOUNTING: Organization
-- ======================
CREATE FOREIGN TABLE unified_accounting_organizations (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  legal_name           text,
  currency             text,
  address              jsonb,
  tax_number           text,
  timezone             text,
  website              text,
  fiscal_year_end_month numeric,
  organization_code    text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/organization');

-- ======================
-- ACCOUNTING: Order
-- ======================
CREATE FOREIGN TABLE unified_accounting_orders (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  posted_at            timestamptz,
  contact_id           text,
  account_id           text,
  type                 text,
  currency             text,
  total_amount         numeric,
  shipping_address     jsonb,
  billing_address      jsonb,
  status               text,
  lineitems            jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/order');

-- ======================
-- ACCOUNTING: Purchaseorder
-- ======================
CREATE FOREIGN TABLE unified_accounting_purchaseorders (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  posted_at            timestamptz,
  contact_id           text,
  account_id           text,
  currency             text,
  total_amount         numeric,
  shipping_address     jsonb,
  billing_address      jsonb,
  status               text,
  lineitems            jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/purchaseorder');

-- ======================
-- ACCOUNTING: Salesorder
-- ======================
CREATE FOREIGN TABLE unified_accounting_salesorders (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  posted_at            timestamptz,
  contact_id           text,
  account_id           text,
  currency             text,
  total_amount         numeric,
  shipping_address     jsonb,
  billing_address      jsonb,
  status               text,
  lineitems            jsonb,
  sales_channel        text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/salesorder');

-- ======================
-- ACCOUNTING: Report
-- ======================
CREATE FOREIGN TABLE unified_accounting_reports (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  type                 text,
  name                 text,
  currency             text,
  start_at             timestamptz,
  end_at               timestamptz,
  balance_sheet        jsonb,
  profit_and_loss      jsonb,
  trial_balance        jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/report');

-- ======================
-- ACCOUNTING: Balancesheet
-- ======================
CREATE FOREIGN TABLE unified_accounting_balancesheets (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  start_at             timestamptz,
  end_at               timestamptz,
  name                 text,
  currency             text,
  net_assets_amount    numeric,
  assets               jsonb,
  liabilities          jsonb,
  equity               jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/balancesheet');

-- ======================
-- ACCOUNTING: Trialbalance
-- ======================
CREATE FOREIGN TABLE unified_accounting_trialbalances (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  start_at             timestamptz,
  name                 text,
  currency             text,
  end_at               timestamptz,
  total_debit_amount   numeric,
  total_credit_amount  numeric,
  sub_items            jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/trialbalance');

-- ======================
-- ACCOUNTING: Profitloss
-- ======================
CREATE FOREIGN TABLE unified_accounting_profitlosses (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  category_ids         text[],
  start_at             timestamptz,
  end_at               timestamptz,
  name                 text,
  currency             text,
  income               jsonb,
  expenses             jsonb,
  cost_of_goods_sold   jsonb,
  gross_profit_amount  numeric,
  net_profit_amount    numeric,
  income_total_amount  numeric,
  net_income_amount    numeric,
  expenses_total_amount numeric,
  cost_of_goods_sold_total_amount numeric,
  income_sections      jsonb,
  expenses_sections    jsonb,
  cost_of_goods_sold_sections jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/profitloss');

-- ======================
-- ACCOUNTING: Cashflow
-- ======================
CREATE FOREIGN TABLE unified_accounting_cashflows (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  start_at             timestamptz,
  end_at               timestamptz,
  category_ids         text[],
  contact_id           text,
  name                 text,
  currency             text,
  cash_beginning_amount numeric,
  cash_ending_amount   numeric,
  net_change_in_cash_amount numeric,
  operating_sections   jsonb,
  investing_sections   jsonb,
  financing_sections   jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/cashflow');

-- ======================
-- ACCOUNTING: Category
-- ======================
CREATE FOREIGN TABLE unified_accounting_categories (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  is_active            boolean,
  parent_id            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/category');

-- ======================
-- ACCOUNTING: Expense
-- ======================
CREATE FOREIGN TABLE unified_accounting_expenses (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  user_id              text,
  name                 text,
  total_amount         numeric,
  currency             text,
  tax_amount           numeric,
  reimbursed_amount    numeric,
  reimbursed_at        timestamptz,
  approved_at          timestamptz,
  approver_user_id     text,
  lineitems            jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/accounting/{connection_id}/expense');

-- ======================
-- STORAGE: File
-- ======================
CREATE FOREIGN TABLE unified_storage_files (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  parent_id            text,
  user_id              text,
  size                 numeric,
  type                 text,
  mime_type            text,
  permissions          jsonb,
  download_url         text,
  hash                 text,
  data                 text,
  version              text,
  web_url              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/storage/{connection_id}/file');

-- ======================
-- COMMERCE: Item
-- ======================
CREATE FOREIGN TABLE unified_commerce_items (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  public_name          text,
  slug                 text,
  description          text,
  global_code          text,
  public_description   text,
  is_active            boolean,
  is_taxable           boolean,
  vendor_name          text,
  type                 text,
  variants             jsonb,
  tags                 text[],
  media                jsonb,
  collection_ids       text[],
  account_id           text,
  metadata             jsonb,
  raw                  jsonb,
  collections          jsonb
)
SERVER unified_server
OPTIONS (endpoint '/commerce/{connection_id}/item');

-- ======================
-- COMMERCE: Collection
-- ======================
CREATE FOREIGN TABLE unified_commerce_collections (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  public_name          text,
  description          text,
  public_description   text,
  media                jsonb,
  is_visible           boolean,
  is_active            boolean,
  is_featured          boolean,
  tags                 text[],
  type                 text,
  parent_id            text,
  metadata             jsonb,
  item_metadata        jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/commerce/{connection_id}/collection');

-- ======================
-- COMMERCE: Inventory
-- ======================
CREATE FOREIGN TABLE unified_commerce_inventories (
  connection_id        text NOT NULL,
  id                   text,
  updated_at           timestamptz,
  item_id              text,
  item_variant_id      text,
  item_option_id       text,
  location_id          text,
  available            numeric,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/commerce/{connection_id}/inventory');

-- ======================
-- COMMERCE: Location
-- ======================
CREATE FOREIGN TABLE unified_commerce_locations (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  address              jsonb,
  description          text,
  is_active            boolean,
  language_locale      text,
  parent_id            text,
  currency             text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/commerce/{connection_id}/location');

-- ======================
-- COMMERCE: Review
-- ======================
CREATE FOREIGN TABLE unified_commerce_reviews (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  item_id              text,
  item_variant_id      text,
  rating               numeric,
  title                text,
  content              text,
  author_name          text,
  author_email         text,
  author_avatar_url    text,
  author_location      text,
  verified_purchase    boolean,
  helpful_votes        numeric,
  unhelpful_votes      numeric,
  media                jsonb,
  status               text,
  is_verified          boolean,
  is_featured          boolean,
  is_public            boolean,
  comments             jsonb,
  metadata             jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/commerce/{connection_id}/review');

-- ======================
-- COMMERCE: Saleschannel
-- ======================
CREATE FOREIGN TABLE unified_commerce_saleschannels (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  slug                 text,
  description          text,
  is_active            boolean,
  collections          jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/commerce/{connection_id}/saleschannel');

-- ======================
-- PAYMENT: Payment
-- ======================
CREATE FOREIGN TABLE unified_payment_payments (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  total_amount         numeric,
  contact_id           text,
  payment_method       text,
  currency             text,
  notes                text,
  invoice_id           text,
  account_id           text,
  reference            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/payment/{connection_id}/payment');

-- ======================
-- PAYMENT: Link
-- ======================
CREATE FOREIGN TABLE unified_payment_links (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  is_active            boolean,
  lineitems            jsonb,
  currency             text,
  amount               numeric,
  payment_id           text,
  contact_id           text,
  url                  text,
  is_chargeable_now    boolean,
  success_url          text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/payment/{connection_id}/link');

-- ======================
-- PAYMENT: Refund
-- ======================
CREATE FOREIGN TABLE unified_payment_refunds (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  total_amount         numeric,
  payment_id           text,
  currency             text,
  notes                text,
  status               text,
  reference            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/payment/{connection_id}/refund');

-- ======================
-- PAYMENT: Payout
-- ======================
CREATE FOREIGN TABLE unified_payment_payouts (
  connection_id        text NOT NULL,
  id                   text,
  created_at           text,
  updated_at           text,
  total_amount         numeric,
  currency             text,
  notes                text,
  status               text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/payment/{connection_id}/payout');

-- ======================
-- PAYMENT: Subscription
-- ======================
CREATE FOREIGN TABLE unified_payment_subscriptions (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  description          text,
  contact_id           text,
  invoice_id           text,
  current_period_end_at timestamptz,
  current_period_start_at timestamptz,
  canceled_at          timestamptz,
  currency             text,
  start_at             timestamptz,
  end_at               timestamptz,
  status               text,
  month                numeric,
  interval_unit        text,
  day_of_month         numeric,
  day_of_week          numeric,
  interval             numeric,
  lineitems            jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/payment/{connection_id}/subscription');

-- ======================
-- GENAI: Model
-- ======================
CREATE FOREIGN TABLE unified_genai_models (
  connection_id        text NOT NULL,
  id                   text,
  name                 text,
  description          text,
  max_tokens           numeric,
  web_url              text,
  has_temperature      boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/genai/{connection_id}/model');

-- ======================
-- KMS: Space
-- ======================
CREATE FOREIGN TABLE unified_kms_spaces (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  parent_space_id      text,
  parent_id            text,
  is_active            boolean,
  user_id              text,
  parent_page_id       text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/kms/{connection_id}/space');

-- ======================
-- KMS: Page
-- ======================
CREATE FOREIGN TABLE unified_kms_pages (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  title                text,
  type                 text,
  space_id             text,
  parent_page_id       text,
  parent_id            text,
  is_active            boolean,
  user_id              text,
  download_url         text,
  metadata             jsonb,
  has_children         boolean,
  web_url              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/kms/{connection_id}/page');

-- ======================
-- KMS: Comment
-- ======================
CREATE FOREIGN TABLE unified_kms_comments (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  type                 text,
  content_type         text,
  content              text,
  user_id              text,
  page_id              text,
  parent_id            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/kms/{connection_id}/comment');

-- ======================
-- TASK: Project
-- ======================
CREATE FOREIGN TABLE unified_task_projects (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  parent_id            text,
  user_ids             text[],
  group_ids            text[],
  description          text,
  has_tasks            boolean,
  has_children         boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/task/{connection_id}/project');

-- ======================
-- TASK: Task
-- ======================
CREATE FOREIGN TABLE unified_task_tasks (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  project_id           text,
  parent_id            text,
  completed_at         timestamptz,
  status               text,
  notes                text,
  due_at               timestamptz,
  priority             text,
  assigned_user_ids    text[],
  creator_user_id      text,
  follower_user_ids    text[],
  group_ids            text[],
  tags                 text[],
  url                  text,
  attachment_ids       text[],
  metadata             jsonb,
  has_children         boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/task/{connection_id}/task');

-- ======================
-- TASK: Comment
-- ======================
CREATE FOREIGN TABLE unified_task_comments (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  text                 text,
  user_id              text,
  user_name            text,
  task_id              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/task/{connection_id}/comment');

-- ======================
-- TASK: Change
-- ======================
CREATE FOREIGN TABLE unified_task_changes (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  task_id              text,
  user_id              text,
  items                jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/task/{connection_id}/change');

-- ======================
-- SCIM: Users
-- ======================
CREATE FOREIGN TABLE unified_scim_users (
  connection_id        text NOT NULL,
  id                   text,
  schemas              text[],
  externalId           text,
  userType             text,
  userName             text,
  meta                 jsonb,
  name                 jsonb,
  displayName          text,
  nickName             text,
  profileUrl           text,
  title                text,
  preferredLanguage    text,
  locale               text,
  timezone             text,
  active               boolean,
  password             text,
  phoneNumbers         jsonb,
  emails               jsonb,
  ims                  jsonb,
  photos               jsonb,
  addresses            jsonb,
  groups               jsonb,
  entitlements         jsonb,
  roles                jsonb,
  x509Certificates     jsonb,
  urn:ietf:params:scim:schemas:extension:enterprise:2.0:User jsonb,
  urn:ietf:params:scim:schemas:extension:lattice:attributes:1.0:User jsonb,
  urn:ietf:params:scim:schemas:extension:peakon:2.0:User jsonb
)
SERVER unified_server
OPTIONS (endpoint '/scim/{connection_id}/users');

-- ======================
-- SCIM: Groups
-- ======================
CREATE FOREIGN TABLE unified_scim_groups (
  connection_id        text NOT NULL,
  id                   text,
  externalId           text,
  displayName          text,
  groupType            text,
  members              jsonb,
  meta                 jsonb,
  schemas              text[]
)
SERVER unified_server
OPTIONS (endpoint '/scim/{connection_id}/groups');

-- ======================
-- CALENDAR: Calendar
-- ======================
CREATE FOREIGN TABLE unified_calendar_calendars (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  timezone             text,
  primary              boolean,
  is_primary           boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/calendar/{connection_id}/calendar');

-- ======================
-- CALENDAR: Event
-- ======================
CREATE FOREIGN TABLE unified_calendar_events (
  connection_id        text NOT NULL,
  id                   text,
  created_at           text,
  updated_at           text,
  calendar_id          text,
  subject              text,
  start_at             text,
  end_at               text,
  is_all_day           boolean,
  timezone             text,
  notes                text,
  location             text,
  is_free              boolean,
  is_private           boolean,
  status               text,
  organizer            jsonb,
  attendees            jsonb,
  recurring_event_id   text,
  recurrence           jsonb,
  web_url              text,
  has_conference       boolean,
  conference           jsonb,
  attachments          jsonb,
  send_notifications   boolean,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/calendar/{connection_id}/event');

-- ======================
-- CALENDAR: Busy
-- ======================
CREATE FOREIGN TABLE unified_calendar_busies (
  connection_id        text NOT NULL,
  id                   text,
  start_at             timestamptz,
  end_at               timestamptz,
  timezone             text,
  description          text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/calendar/{connection_id}/busy');

-- ======================
-- CALENDAR: Link
-- ======================
CREATE FOREIGN TABLE unified_calendar_links (
  connection_id        text NOT NULL,
  id                   text,
  created_at           text,
  updated_at           text,
  name                 text,
  url                  text,
  duration             numeric,
  description          text,
  is_active            boolean,
  price_amount         numeric,
  price_currency       text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/calendar/{connection_id}/link');

-- ======================
-- CALENDAR: Recording
-- ======================
CREATE FOREIGN TABLE unified_calendar_recordings (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  start_at             timestamptz,
  end_at               timestamptz,
  expires_at           timestamptz,
  event_id             text,
  web_url              text,
  media                jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/calendar/{connection_id}/recording');

-- ======================
-- LMS: Course
-- ======================
CREATE FOREIGN TABLE unified_lms_courses (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  is_private           boolean,
  is_active            boolean,
  price_amount         numeric,
  languages            text[],
  categories           text[],
  currency             text,
  media                jsonb,
  instructor_ids       text[],
  student_ids          text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/lms/{connection_id}/course');

-- ======================
-- LMS: Class
-- ======================
CREATE FOREIGN TABLE unified_lms_classes (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  media                jsonb,
  course_id            text,
  instructor_ids       text[],
  student_ids          text[],
  languages            text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/lms/{connection_id}/class');

-- ======================
-- LMS: Student
-- ======================
CREATE FOREIGN TABLE unified_lms_students (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  emails               jsonb,
  telephones           jsonb,
  address              jsonb,
  image_url            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/lms/{connection_id}/student');

-- ======================
-- LMS: Instructor
-- ======================
CREATE FOREIGN TABLE unified_lms_instructors (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  first_name           text,
  last_name            text,
  emails               jsonb,
  title                text,
  telephones           jsonb,
  image_url            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/lms/{connection_id}/instructor');

-- ======================
-- REPO: Organization
-- ======================
CREATE FOREIGN TABLE unified_repo_organizations (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  avatar_url           text,
  web_url              text,
  user_ids             text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/repo/{connection_id}/organization');

-- ======================
-- REPO: Repository
-- ======================
CREATE FOREIGN TABLE unified_repo_repositories (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  description          text,
  owner                text,
  is_private           boolean,
  web_url              text,
  org_id               text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/repo/{connection_id}/repository');

-- ======================
-- REPO: Branch
-- ======================
CREATE FOREIGN TABLE unified_repo_branches (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  repo_id              text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/repo/{connection_id}/branch');

-- ======================
-- REPO: Commit
-- ======================
CREATE FOREIGN TABLE unified_repo_commits (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  user_id              text,
  repo_id              text,
  message              text,
  branch_id            text,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/repo/{connection_id}/commit');

-- ======================
-- REPO: Pullrequest
-- ======================
CREATE FOREIGN TABLE unified_repo_pullrequests (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  user_ids             text[],
  repo_id              text,
  status               text,
  labels               text[],
  closed_at            timestamptz,
  commit_ids           text[],
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/repo/{connection_id}/pullrequest');

-- ======================
-- METADATA: Metadata
-- ======================
CREATE FOREIGN TABLE unified_metadata_metadatas (
  connection_id        text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  slug                 text,
  format               text,
  original_format      text,
  options              text[],
  object_type          text,
  objects              jsonb,
  raw                  jsonb
)
SERVER unified_server
OPTIONS (endpoint '/metadata/{connection_id}/metadata');

