-- ======================
-- ADS: Organization
-- ======================
CREATE TABLE unified_ads_organization (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  currency             text,
  timezone             text,
  parent_id            text,
  raw                  jsonb
);
-- ======================
-- ADS: Campaign
-- ======================
CREATE TABLE unified_ads_campaign (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  organization_id      text,
  status               text,
  start_at             timestamptz,
  end_at               timestamptz,
  budget_amount        numeric,
  budget_period        text,
  total_spend_amount   numeric,
  targeting            jsonb,
  goal                 text,
  planned_spend_amount numeric,
  frequency_cap        jsonb,
  advertising_channel_type text,
  campaign_budget_identifier text,
  currency             text,
  category             text,
  has_eu_political_ads boolean,
  raw                  jsonb
);
-- ======================
-- ADS: Creative
-- ======================
CREATE TABLE unified_ads_creative (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  campaign_id          text,
  group_id             text,
  item_id              text,
  organization_id      text,
  status               text,
  creative_type        text,
  hosting_source       text,
  width                numeric,
  height               numeric,
  asset_urls           text[],
  link_url             text,
  body                 text,
  title                text,
  cta                  text,
  third_party_tag      text,
  vast_tag_url         text,
  external_creative_reference text,
  external_placement_reference text,
  external_ad_reference text,
  promoted             jsonb,
  path1                text,
  path2                text,
  raw                  jsonb
);
-- ======================
-- ADS: Insertionorder
-- ======================
CREATE TABLE unified_ads_insertionorder (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  organization_id      text,
  campaign_id          text,
  status               text,
  pacing               jsonb,
  frequency_cap        jsonb,
  kpi                  jsonb,
  budget_unit          text,
  budget_segments      jsonb,
  bid_strategy         jsonb,
  reference            text,
  raw                  jsonb
);
-- ======================
-- ADS: Group
-- ======================
CREATE TABLE unified_ads_group (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  parent_id            text,
  campaign_id          text,
  organization_id      text,
  insertionorder_id    text,
  status               text,
  targeting            jsonb,
  bid_amount           numeric,
  bid_strategy         jsonb,
  budget_amount        numeric,
  budget_period        text,
  budget_allocation_type text,
  start_at             timestamptz,
  end_at               timestamptz,
  budget_unit          text,
  budget_max_amount    numeric,
  type                 text,
  has_eu_political_ads boolean,
  pacing               jsonb,
  frequency_cap        jsonb,
  creative_ids         text[],
  optimization_goal    text,
  billing_event        text,
  currency             text,
  promoted             jsonb,
  raw                  jsonb
);
-- ======================
-- ADS: Ad
-- ======================
CREATE TABLE unified_ads_ad (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  campaign_id          text,
  group_id             text,
  organization_id      text,
  status               text,
  ad_type              text,
  creative_ids         text[],
  creative_asset_url   text,
  ad_copy              text,
  headline             text,
  description          text,
  cta                  text,
  final_url            text,
  display_url          text,
  path1                text,
  path2                text,
  promoted             jsonb,
  raw                  jsonb
);
-- ======================
-- ADS: Report
-- ======================
CREATE TABLE unified_ads_report (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  currency             text,
  metrics              jsonb,
  start_at             timestamptz,
  end_at               timestamptz,
  organization_id      text,
  raw                  jsonb
);
-- ======================
-- ADS: Target
-- ======================
CREATE TABLE unified_ads_target (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  name                 text,
  value                text,
  type                 text,
  raw                  jsonb
);
-- ======================
-- ADS: Promoted
-- ======================
CREATE TABLE unified_ads_promoted (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  name                 text,
  type                 text
);
