-- 001_extensions_and_types.sql
-- Enable necessary extensions and define Global ENUMs per ORIGIN

-- UUID support (v4 and v5)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Crypto support (hashing, random)
CREATE EXTENSION IF NOT EXISTS pgcrypto;

-- Text Search
CREATE EXTENSION IF NOT EXISTS btree_gin;

-- === ENUMS (Origin Standard) ===

-- User Role
DO $$ BEGIN
    CREATE TYPE public.user_role AS ENUM ('user', 'creator', 'premium', 'moderator', 'admin');
EXCEPTION
    WHEN duplicate_object THEN null;
END $$;

-- Visibility
DO $$ BEGIN
    CREATE TYPE public.visibility AS ENUM ('public', 'unlisted', 'private');
EXCEPTION
    WHEN duplicate_object THEN null;
END $$;

-- Message Type
DO $$ BEGIN
    CREATE TYPE public.message_type AS ENUM ('text', 'image', 'audio', 'video', 'file', 'system');
EXCEPTION
    WHEN duplicate_object THEN null;
END $$;

-- Order Status
DO $$ BEGIN
    CREATE TYPE public.order_status AS ENUM ('pending', 'paid', 'processing', 'completed', 'cancelled', 'refunded');
EXCEPTION
    WHEN duplicate_object THEN null;
END $$;

-- Playlist Permission (Legacy/Lab compatibility)
DO $$ BEGIN
    CREATE TYPE public.playlist_permission AS ENUM ('read', 'write', 'admin');
EXCEPTION
    WHEN duplicate_object THEN null;
END $$;