FROM php:8.2-fpm-bullseye

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    bash \
    curl \
    git \
    unzip \
    libpng-dev \
    libjpeg-turbo-progs \
    libfreetype6-dev \
    libzip-dev \
    libpq-dev \
    libonig-dev \
    supervisor \
    nodejs \
    npm \
    && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install \
        pdo \
        pdo_pgsql \
        pgsql \
        mbstring \
        exif \
        pcntl \
        bcmath \
        gd \
        zip \
        opcache

# Install Redis extension (optional - can be added via composer if needed)
# RUN pecl install redis && docker-php-ext-enable redis || true

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Configure PHP
COPY docker/php/php.ini /usr/local/etc/php/conf.d/custom.ini

WORKDIR /var/www/html

# Copy project files
COPY . .

# Install dependencies (skip if vendor already exists)
RUN if [ ! -d "vendor" ]; then \
    composer install --no-interaction --prefer-dist --optimize-autoloader; \
fi

RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache

EXPOSE 9000

CMD ["php-fpm"]
