-- Script 1: Options Flow Analysis SQL Query Template
-- Replace this with your actual Script 1 SQL query
-- Use $1, $2, $3, etc. for parameter placeholders

-- Example structure (replace with actual Script 1 SQL):
/*
WITH cfg AS (
  SELECT 
    $1::date AS start_day,
    $2::date AS end_day,
    $3::numeric AS tol_pct,
    $4::numeric AS per_print_min_notional,
    -- Add other config parameters here
    100 AS max_results
)
SELECT 
  of.symbol,
  of.type,
  of.strike,
  of.expiration,
  of.total_premium,
  of.volume,
  of.sentiment,
  of.volume_ratio,
  of.execution_time,
  of.rocket_score,
  of.created_at,
  -- Add computed fields from Script 1
  CASE 
    WHEN of.type = 'CALL' AND of.sentiment > 0.6 THEN 'BULLISH'
    WHEN of.type = 'PUT' AND of.sentiment < 0.4 THEN 'BEARISH'
    ELSE 'NEUTRAL'
  END AS flow_direction,
  ABS(of.strike - sp.current_price) / sp.current_price AS distance_from_atm
FROM options_flow of
CROSS JOIN cfg
LEFT JOIN (
  -- Add any joins needed for price data, etc.
  SELECT symbol, current_price FROM stock_prices
) sp ON sp.symbol = of.symbol
WHERE of.created_at >= cfg.start_day
  AND of.created_at <= cfg.end_day
  AND of.total_premium >= cfg.per_print_min_notional
ORDER BY of.created_at DESC, of.total_premium DESC
LIMIT $5::integer;
*/

-- INSTRUCTIONS:
-- 1. Copy your complete Script 1 SQL query here
-- 2. Replace date literals with $1, $2, etc.
-- 3. Replace numeric literals with parameter placeholders
-- 4. Ensure all parameters are properly typed (::date, ::numeric, ::integer)
-- 5. Update the buildOptionsFlowParams() function in optionsFlowQuery.js to match parameter order

