x-defaults: &default-env
    PHP_DISPLAY_ERRORS: "${PHP_DISPLAY_ERRORS:-On}"
    PHP_ERROR_REPORTING: "${PHP_ERROR_REPORTING:-E_ALL}"
    PHP_MEMORY_LIMIT: "${PHP_MEMORY_LIMIT:-256M}"
    PHP_POST_MAX_SIZE: "${PHP_POST_MAX_SIZE:-100M}"
    PHP_UPLOAD_MAX_FILESIZE: "${PHP_UPLOAD_MAX_FILESIZE:-60M}"
    PHP_MAX_EXECUTION_TIME: "${PHP_MAX_EXECUTION_TIME:-60}"
    PHP_DATE_TIMEZONE: "${PHP_DATE_TIMEZONE:-Europe/Lisbon}"
    XDEBUG_MODE: "${XDEBUG_MODE:-debug,develop,coverage,gcstats,profile,trace}"
    XDEBUG_START_WITH_REQUEST: "${XDEBUG_START_WITH_REQUEST:-yes}"
    XDEBUG_CLIENT_PORT: "${XDEBUG_CLIENT_PORT:-9003}"
    XDEBUG_LOG: "${XDEBUG_LOG:-/tmp/xdebug.log}"
    XDEBUG_LOG_LEVEL: "${XDEBUG_LOG_LEVEL:-7}"
    XDEBUG_IDEKEY: "${XDEBUG_IDEKEY:-VSCODE}"
    PHP_VERSION: "${PHP_VERSION:-8.2}"
    SERVER_NAME: "${SERVER_NAME:-host.docker.internal}"

services:
    backoffice-marketplace:
        build:
            context: ./php-img
        extra_hosts:
            - "host.docker.internal:host-gateway"
        ports:
            - "8081:80"
        volumes:
            - ../Backoffice_Marketplace:/var/www/html
            - ../Shared:/var/www/html/shared
            - ./php-img/config/apache-backoffice-marketplace.conf:/etc/apache2/sites-available/000-default.conf
            - ./php-img/config/apache-backoffice-marketplace.conf:/etc/apache2/sites-enabled/000-default.conf
            - ./php-img/config/xdebug.ini:/etc/php/8.2/apache2/conf.d/xdebug.ini
        env_file:
            - ../Backoffice_Marketplace/.env
        environment:
            <<: *default-env
            APPLICATION_ENV: "${APPLICATION_ENV:-development}"
            SERVER_NAME: "backoffice.coimbra.local"
            XDEBUG_CLIENT_PORT: 9004
        networks:
            - app-network
        depends_on:
            - system-database
            - mailhog

    bi:
        build:
            context: ./php-img
        extra_hosts:
            - "host.docker.internal:host-gateway"
        ports:
            - "8082:80"
        volumes:
            - ../BI:/var/www/html
            - ../Shared:/var/www/html/shared
            - ./php-img/config/apache-bi.conf:/etc/apache2/sites-available/000-default.conf
            - ./php-img/config/apache-bi.conf:/etc/apache2/sites-enabled/000-default.conf
            - ./php-img/config/xdebug.ini:/etc/php/8.2/apache2/conf.d/xdebug.ini
        env_file:
            - ../BI/.env
        environment:
            <<: *default-env
            APPLICATION_ENV: "${APPLICATION_ENV:-development}"
            SERVER_NAME: "bi.coimbra.local"
            XDEBUG_CLIENT_PORT: 9005
        networks:
            - app-network
        depends_on:
            - system-database
            - mailhog

    system-database:
        build:
            context: ./mariadb-img
        container_name: system-database
        ports:
            - "3306:3306"
        environment:
            MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
            MYSQL_USER: "${MYSQL_USER}"
            MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
            MYSQL_DATABASE_1: "${MYSQL_DATABASE_1}"
            MYSQL_DATABASE_2: "${MYSQL_DATABASE_2}"
        networks:
            - app-network
        volumes:
            - system-database-data:/var/lib/mysql
            - ./mariadb-img:/docker-entrypoint-initdb.d

    mailhog:
        image: mailhog/mailhog
        ports:
            - "1025:1025" # SMTP server
            - "8025:8025" # Web UI
        networks:
            - app-network

    libretranslate:
        build:
            context: ./libretranslate
        ports:
            - "5000:5000"
        networks:
            - app-network
        volumes:
            - libretranslate-packages:/app/packages
        command: --host 0.0.0.0 --load-only pt,en,es,de,fr

volumes:
    system-database-data:
    libretranslate-packages:

networks:
    app-network:
        driver: bridge
