-- Raw ICE certified warehouse stocks — technical ingestion layer.
--
-- Reads daily stock report gzip CSVs from the landing directory.
-- All values are varchar; casting happens in foundation.fct_ice_warehouse_stocks.
--
-- Source: ICE Report Center (Coffee C certified warehouse stocks)
-- Coverage: varies by download history
-- Frequency: daily (ICE updates after market close)

MODEL (
  name raw.ice_warehouse_stocks,
  kind FULL,
  cron '@daily',
  columns (
    report_date             varchar,
    total_certified_bags    varchar,
    pending_grading_bags    varchar,
    filename                varchar
  )
);

SELECT
  report_date,
  total_certified_bags,
  pending_grading_bags,
  filename
FROM read_csv(
  @ice_stocks_glob(),
  delim = ',',
  encoding = 'utf-8',
  compression = 'gzip',
  header = true,
  union_by_name = true,
  filename = true,
  all_varchar = true,
  ignore_errors = true
)
