-- Raw ICE certified stock aging report — technical ingestion layer.
--
-- Reads monthly aging report gzip CSVs from the landing directory.
-- All values are varchar; casting happens in foundation.fct_ice_aging_stocks.
--
-- Source: ICE Report Center (Certified Stock Aging Report)
-- Coverage: varies by download history
-- Frequency: monthly (ICE updates after each delivery month)

MODEL (
  name raw.ice_aging_stocks,
  kind FULL,
  cron '@daily',
  columns (
    report_date             varchar,
    age_bucket              varchar,
    antwerp_bags            varchar,
    hamburg_bremen_bags     varchar,
    houston_bags            varchar,
    miami_bags              varchar,
    new_orleans_bags        varchar,
    new_york_bags           varchar,
    total_bags              varchar,
    filename                varchar
  )
);

SELECT
  report_date,
  age_bucket,
  antwerp_bags,
  hamburg_bremen_bags,
  houston_bags,
  miami_bags,
  new_orleans_bags,
  new_york_bags,
  total_bags,
  filename
FROM read_csv(
  @ice_aging_glob(),
  delim = ',',
  encoding = 'utf-8',
  compression = 'gzip',
  header = true,
  union_by_name = true,
  filename = true,
  all_varchar = true,
  ignore_errors = true
)
