-- Drop the generic professionals table approach; use per-profession profile tables
-- Portfolio and services stay shared (referenced by user_id + profession_key)

-- 1. PHOTOGRAPHER PROFILES
CREATE TABLE IF NOT EXISTS photographer_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    specialties TEXT[] DEFAULT '{}',        -- e.g. ['Wedding', 'Portrait', 'Commercial']
    camera_brands TEXT[] DEFAULT '{}',      -- e.g. ['Sony', 'Canon']
    studio_available BOOLEAN NOT NULL DEFAULT false,
    outdoor_shoots BOOLEAN NOT NULL DEFAULT true,
    travel_radius_km INTEGER DEFAULT 50,
    starting_price_inr INTEGER DEFAULT 0,   -- in paise
    -- Verification & status
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING', -- PENDING, APPROVED, REJECTED, SUSPENDED
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 2. TUTOR PROFILES
CREATE TABLE IF NOT EXISTS tutor_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    subjects TEXT[] DEFAULT '{}',           -- e.g. ['Math', 'Physics', 'Hindi']
    board_types TEXT[] DEFAULT '{}',        -- e.g. ['CBSE', 'ICSE', 'IB']
    qualification VARCHAR(255),             -- e.g. 'B.Tech IIT Delhi'
    teaches_online BOOLEAN NOT NULL DEFAULT true,
    teaches_offline BOOLEAN NOT NULL DEFAULT true,
    experience_years INTEGER DEFAULT 0,
    hourly_rate_inr INTEGER DEFAULT 0,      -- in paise
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 3. MAKEUP ARTIST PROFILES
CREATE TABLE IF NOT EXISTS makeup_artist_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    specializations TEXT[] DEFAULT '{}',   -- e.g. ['Bridal', 'Editorial', 'SFX']
    kit_brands TEXT[] DEFAULT '{}',        -- e.g. ['MAC', 'NARS', 'NYX']
    home_service BOOLEAN NOT NULL DEFAULT true,
    studio_available BOOLEAN NOT NULL DEFAULT false,
    starting_price_inr INTEGER DEFAULT 0,
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 4. DEVELOPER PROFILES
CREATE TABLE IF NOT EXISTS developer_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    tech_stack TEXT[] DEFAULT '{}',        -- e.g. ['Rust', 'React', 'PostgreSQL']
    github_url VARCHAR(500),
    portfolio_url VARCHAR(500),
    experience_years INTEGER DEFAULT 0,
    availability VARCHAR(50) DEFAULT 'FULL_TIME', -- FULL_TIME, PART_TIME, FREELANCE
    hourly_rate_inr INTEGER DEFAULT 0,
    remote_ok BOOLEAN NOT NULL DEFAULT true,
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 5. VIDEO EDITOR PROFILES
CREATE TABLE IF NOT EXISTS video_editor_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    software_skills TEXT[] DEFAULT '{}',   -- e.g. ['Premiere Pro', 'DaVinci Resolve']
    style_tags TEXT[] DEFAULT '{}',        -- e.g. ['Cinematic', 'Corporate', 'Reels']
    turnaround_days INTEGER DEFAULT 7,
    reel_url VARCHAR(500),
    starting_price_inr INTEGER DEFAULT 0,
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 6. GRAPHIC DESIGNER PROFILES
CREATE TABLE IF NOT EXISTS graphic_designer_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    design_tools TEXT[] DEFAULT '{}',      -- e.g. ['Figma', 'Illustrator', 'Photoshop']
    style_tags TEXT[] DEFAULT '{}',        -- e.g. ['Minimalist', 'Bold', 'Corporate']
    brand_experience BOOLEAN NOT NULL DEFAULT false,
    portfolio_url VARCHAR(500),
    starting_price_inr INTEGER DEFAULT 0,
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 7. SOCIAL MEDIA MANAGER PROFILES
CREATE TABLE IF NOT EXISTS social_media_manager_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    platforms TEXT[] DEFAULT '{}',          -- e.g. ['Instagram', 'LinkedIn', 'YouTube']
    industries TEXT[] DEFAULT '{}',          -- e.g. ['F&B', 'Fashion', 'Real Estate']
    content_types TEXT[] DEFAULT '{}',       -- e.g. ['Reels', 'Carousels', 'Stories']
    avg_follower_growth_pct INTEGER DEFAULT 0,
    starting_price_inr INTEGER DEFAULT 0,
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 8. FITNESS TRAINER PROFILES
CREATE TABLE IF NOT EXISTS fitness_trainer_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    display_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    disciplines TEXT[] DEFAULT '{}',        -- e.g. ['Yoga', 'HIIT', 'Zumba', 'CrossFit']
    certifications TEXT[] DEFAULT '{}',     -- e.g. ['ACE', 'NASM', 'Yoga Alliance RYT']
    online_sessions BOOLEAN NOT NULL DEFAULT true,
    home_visits BOOLEAN NOT NULL DEFAULT false,
    gym_based BOOLEAN NOT NULL DEFAULT false,
    per_session_rate_inr INTEGER DEFAULT 0,
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 9. CATERING SERVICES PROFILES
CREATE TABLE IF NOT EXISTS catering_service_profiles (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE UNIQUE,
    business_name VARCHAR(255) NOT NULL,
    bio TEXT,
    location VARCHAR(255),
    -- Profession-specific
    cuisine_types TEXT[] DEFAULT '{}',       -- e.g. ['North Indian', 'Continental', 'Vegan']
    event_types TEXT[] DEFAULT '{}',         -- e.g. ['Wedding', 'Corporate', 'Birthday']
    min_guests INTEGER DEFAULT 10,
    max_guests INTEGER DEFAULT 500,
    has_setup_team BOOLEAN NOT NULL DEFAULT true,
    has_serving_staff BOOLEAN NOT NULL DEFAULT true,
    price_per_head_inr INTEGER DEFAULT 0,    -- in paise
    status VARCHAR(50) NOT NULL DEFAULT 'PENDING',
    rejection_reason TEXT,
    approved_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Shared: portfolio_items now uses user_id + profession_key (no foreign key to professionals)
-- Drop the professionals-table FK if it was added before
ALTER TABLE portfolio_items
    ADD COLUMN IF NOT EXISTS user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    ADD COLUMN IF NOT EXISTS profession_key VARCHAR(50);

ALTER TABLE services
    ADD COLUMN IF NOT EXISTS user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    ADD COLUMN IF NOT EXISTS profession_key VARCHAR(50);

-- Lead requests: use user_id instead of professional_id foreign key  
ALTER TABLE lead_requests
    ADD COLUMN IF NOT EXISTS professional_user_id UUID REFERENCES users(id) ON DELETE CASCADE;

-- Indexes
CREATE INDEX IF NOT EXISTS idx_photographer_profiles_status ON photographer_profiles(status);
CREATE INDEX IF NOT EXISTS idx_tutor_profiles_status ON tutor_profiles(status);
CREATE INDEX IF NOT EXISTS idx_makeup_artist_profiles_status ON makeup_artist_profiles(status);
CREATE INDEX IF NOT EXISTS idx_developer_profiles_status ON developer_profiles(status);
CREATE INDEX IF NOT EXISTS idx_video_editor_profiles_status ON video_editor_profiles(status);
CREATE INDEX IF NOT EXISTS idx_graphic_designer_profiles_status ON graphic_designer_profiles(status);
CREATE INDEX IF NOT EXISTS idx_social_media_manager_profiles_status ON social_media_manager_profiles(status);
CREATE INDEX IF NOT EXISTS idx_fitness_trainer_profiles_status ON fitness_trainer_profiles(status);
CREATE INDEX IF NOT EXISTS idx_catering_service_profiles_status ON catering_service_profiles(status);
CREATE INDEX IF NOT EXISTS idx_portfolio_items_user_id ON portfolio_items(user_id);
CREATE INDEX IF NOT EXISTS idx_services_user_id ON services(user_id);
