/*
  # Add Team Management Table

  1. New Tables
    - `team_members`
      - `id` (uuid, primary key)
      - `name` (text)
      - `role` (text)
      - `image_url` (text)
      - `description` (text)
      - `linkedin_url` (text)
      - `twitter_url` (text)
      - `github_url` (text)
      - `is_active` (boolean)
      - `sort_order` (integer)
      - `created_at` (timestamp)

  2. Security
    - Enable RLS on team_members table
    - Add policies for public read access
    - Add policies for admin management
*/

-- Team members table
CREATE TABLE IF NOT EXISTS team_members (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  name text NOT NULL,
  role text NOT NULL,
  image_url text NOT NULL,
  description text NOT NULL,
  linkedin_url text,
  twitter_url text,
  github_url text,
  is_active boolean DEFAULT true,
  sort_order integer DEFAULT 0,
  created_at timestamptz DEFAULT now()
);

-- Enable Row Level Security
ALTER TABLE team_members ENABLE ROW LEVEL SECURITY;

-- Public read policy for team members
CREATE POLICY "Anyone can view active team members"
  ON team_members
  FOR SELECT
  TO anon, authenticated
  USING (is_active = true);

-- Admin policies for team management
CREATE POLICY "Authenticated users can manage team"
  ON team_members
  FOR ALL
  TO authenticated
  USING (true)
  WITH CHECK (true);

-- Anonymous admin policies (for demo purposes)
CREATE POLICY "Allow anon insert team" ON team_members
  FOR INSERT TO anon
  WITH CHECK (true);

CREATE POLICY "Allow anon update team" ON team_members
  FOR UPDATE TO anon
  USING (true)
  WITH CHECK (true);

CREATE POLICY "Allow anon delete team" ON team_members
  FOR DELETE TO anon
  USING (true);

-- Insert sample team members
INSERT INTO team_members (name, role, image_url, description, linkedin_url, twitter_url, github_url, sort_order) VALUES
('Alex Johnson', 'CEO & Founder', 'https://images.pexels.com/photos/2379004/pexels-photo-2379004.jpeg?auto=compress&cs=tinysrgb&w=300', 'Visionary leader with 10+ years in digital transformation', '#', '#', '#', 1),
('Sarah Chen', 'CTO', 'https://images.pexels.com/photos/3781545/pexels-photo-3781545.jpeg?auto=compress&cs=tinysrgb&w=300', 'Technical expert specializing in scalable web solutions', '#', '#', '#', 2),
('Michael Rodriguez', 'Lead Developer', 'https://images.pexels.com/photos/1222271/pexels-photo-1222271.jpeg?auto=compress&cs=tinysrgb&w=300', 'Full-stack developer with expertise in modern frameworks', '#', '#', '#', 3),
('Emily Davis', 'UI/UX Designer', 'https://images.pexels.com/photos/3785077/pexels-photo-3785077.jpeg?auto=compress&cs=tinysrgb&w=300', 'Creative designer focused on user-centered design principles', '#', '#', '#', 4),
('David Park', 'Digital Marketing Manager', 'https://images.pexels.com/photos/1043471/pexels-photo-1043471.jpeg?auto=compress&cs=tinysrgb&w=300', 'Marketing strategist with proven ROI track record', '#', '#', '#', 5),
('Lisa Thompson', 'Project Manager', 'https://images.pexels.com/photos/3767392/pexels-photo-3767392.jpeg?auto=compress&cs=tinysrgb&w=300', 'Agile project management expert ensuring timely delivery', '#', '#', '#', 6);