-- Analytical fact table: trade_fills
-- Fill and execution records from broker.
-- Partitioned by dt on MinIO.
-- Path: s3://stonks-lakehouse/warehouse/trade_fills/dt={yyyy-mm-dd}/part-*.parquet
-- Requirements: 9.4, 9.5, 10.1, 10.3
-- Design ref: Section 7 (lake.trade_fills)

CREATE TABLE IF NOT EXISTS lakehouse.stonks.trade_fills (
    fill_id           VARCHAR,
    order_id          VARCHAR,
    ticker            VARCHAR,
    side              VARCHAR,
    fill_price        DOUBLE,
    fill_quantity     DOUBLE,
    commission        DOUBLE,
    broker_account    VARCHAR,
    filled_at         TIMESTAMP(6) WITH TIME ZONE,
    dt                DATE
) WITH (
    format = 'PARQUET',
    partitioned_by = ARRAY['dt'],
    external_location = 's3a://stonks-lakehouse/warehouse/trade_fills/'
);
