-- 1. Clients Table RLS
ALTER TABLE clients ENABLE ROW LEVEL SECURITY;
CREATE POLICY select_policy ON clients FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY insert_policy ON clients FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY update_policy ON clients FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY delete_policy ON clients FOR DELETE USING (auth.uid() = user_id);

-- 2. Projects Table RLS
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
CREATE POLICY select_policy ON projects FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY insert_policy ON projects FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY update_policy ON projects FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY delete_policy ON projects FOR DELETE USING (auth.uid() = user_id);

-- 3. Tasks Table RLS
ALTER TABLE tasks ENABLE ROW LEVEL SECURITY;
CREATE POLICY select_policy ON tasks FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY insert_policy ON tasks FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY update_policy ON tasks FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY delete_policy ON tasks FOR DELETE USING (auth.uid() = user_id);

-- 4. Time Entries Table RLS
ALTER TABLE time_entries ENABLE ROW LEVEL SECURITY;
CREATE POLICY select_policy ON time_entries FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY insert_policy ON time_entries FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY update_policy ON time_entries FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY delete_policy ON time_entries FOR DELETE USING (auth.uid() = user_id);

-- 5. Briefs Table RLS
ALTER TABLE briefs ENABLE ROW LEVEL SECURITY;
CREATE POLICY select_policy ON briefs FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY insert_policy ON briefs FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY update_policy ON briefs FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY delete_policy ON briefs FOR DELETE USING (auth.uid() = user_id);
