-- Raw KC=F Coffee C futures prices — technical ingestion layer.
--
-- Reads daily OHLCV gzip CSVs from the landing directory. All values are
-- varchar; casting happens in foundation.fct_coffee_prices.
--
-- Source: Yahoo Finance via yfinance (KC=F ticker)
-- Coverage: 1971-present (historical futures data)
-- Frequency: daily (trading days only)

MODEL (
  name raw.coffee_prices,
  kind FULL,
  grain (Date),
  cron '@daily',
  columns (
    Date        varchar,
    Open        varchar,
    High        varchar,
    Low         varchar,
    Close       varchar,
    Adj_Close   varchar,
    Volume      varchar,
    filename    varchar
  )
);

SELECT
  "Date"      AS Date,
  "Open"      AS Open,
  "High"      AS High,
  "Low"       AS Low,
  "Close"     AS Close,
  "Adj Close" AS Adj_Close,
  "Volume"    AS Volume,
  filename
FROM read_csv(
  @prices_glob(),
  delim = ',',
  encoding = 'utf-8',
  compression = 'gzip',
  header = true,
  union_by_name = true,
  filename = true,
  all_varchar = true,
  ignore_errors = true
)
