-- ─────────────────────────────────────────────────────────────
-- WASL — PostgreSQL initialization
-- Runs once when the postgres container initializes the data dir.
-- ─────────────────────────────────────────────────────────────

-- Ensure required extensions are enabled for the WASL database
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";       -- gen_random_uuid() / uuid-ossp
CREATE EXTENSION IF NOT EXISTS "pgcrypto";         -- encryption helpers (pgp_sym_encrypt)
CREATE EXTENSION IF NOT EXISTS "citext";           -- case-insensitive text (emails)
CREATE EXTENSION IF NOT EXISTS "pg_trgm";          -- trigram fuzzy search (phone lookup)
CREATE EXTENSION IF NOT EXISTS "btree_gin";        -- composite GIN indexes

-- Create the test database if running in development
SELECT 'CREATE DATABASE wasl_testing OWNER wasl'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'wasl_testing')\gexec

-- Set default search path
ALTER DATABASE wasl SET search_path TO public;
ALTER DATABASE wasl SET timezone TO 'Asia/Damascus';
