-- ============================================================
-- PostgreSQL Initialization — SocialAI Platform
-- Creates extensions and default settings
-- ============================================================

-- Enable required extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE EXTENSION IF NOT EXISTS "pg_trgm";       -- For full-text search
CREATE EXTENSION IF NOT EXISTS "btree_gin";     -- For GIN indexes
CREATE EXTENSION IF NOT EXISTS "unaccent";      -- For accent-insensitive search

-- Create system_settings table (used by AdminSettingsController)
CREATE TABLE IF NOT EXISTS system_settings (
    id          SERIAL PRIMARY KEY,
    section     VARCHAR(50)  NOT NULL,
    key         VARCHAR(100) NOT NULL,
    value       TEXT,
    created_at  TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at  TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    UNIQUE(section, key)
);

-- Set timezone
SET timezone = 'UTC';

-- Performance settings
ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_statements';
ALTER SYSTEM SET log_min_duration_statement = '1000';
ALTER SYSTEM SET max_connections = '200';