-- Mission Control Briefs Database Schema
-- Run these in Supabase SQL Editor

-- Morning Briefs Table
CREATE TABLE IF NOT EXISTS morning_briefs (
  id SERIAL PRIMARY KEY,
  date TEXT NOT NULL,
  weather TEXT,
  market JSONB DEFAULT '{}',
  priorities JSONB DEFAULT '[]',
  goal TEXT,
  leads JSONB DEFAULT '[]',
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- EOD Briefs Table
CREATE TABLE IF NOT EXISTS eod_briefs (
  id SERIAL PRIMARY KEY,
  date TEXT NOT NULL,
  completed JSONB DEFAULT '[]',
  progress JSONB DEFAULT '{}',
  council JSONB DEFAULT '{}',
  tomorrow JSONB DEFAULT '[]',
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Amun Sessions Table
CREATE TABLE IF NOT EXISTS amun_sessions (
  id SERIAL PRIMARY KEY,
  date TEXT NOT NULL,
  tests JSONB DEFAULT '[]',
  bugs JSONB DEFAULT '[]',
  quality TEXT,
  recommendations JSONB DEFAULT '[]',
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Enable RLS
ALTER TABLE morning_briefs ENABLE ROW LEVEL SECURITY;
ALTER TABLE eod_briefs ENABLE ROW LEVEL SECURITY;
ALTER TABLE amun_sessions ENABLE ROW LEVEL SECURITY;

-- Allow public read/write (can be restricted later)
CREATE POLICY "Allow all" ON morning_briefs FOR ALL USING (true) WITH CHECK (true);
CREATE POLICY "Allow all" ON eod_briefs FOR ALL USING (true) WITH CHECK (true);
CREATE POLICY "Allow all" ON amun_sessions FOR ALL USING (true) WITH CHECK (true);
