version: '3.8'

services:
  # Next.js Application
  app:
    container_name: nordicstorium-app
    build:
      context: .
      dockerfile: Dockerfile.prod
      args:
        NEXT_PUBLIC_APP_URL: "https://store.abrahem.se"
        NEXT_PUBLIC_API_URL: "https://store.abrahem.se/api"
    restart: always
    ports:
      - "3005:3000"
    environment:
      - NEXT_PUBLIC_APP_URL=https://store.abrahem.se
      - NEXT_PUBLIC_API_URL=https://store.abrahem.se/api
      - DATABASE_URL=mysql://${DB_USER}:${DB_PASSWORD}@db:3306/${DB_NAME}
      - DB_HOST=db
      - DB_PORT=3306
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - IN_DOCKER=true
      - JWT_SECRET=${JWT_SECRET}
      - NODE_ENV=production
      - HOSTNAME=0.0.0.0
      - AUTH_URL=https://store.abrahem.se
      - AUTH_TRUST_HOST=true
      - NEXTAUTH_URL=https://store.abrahem.se
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT}
      - SMTP_SECURE=${SMTP_SECURE}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASS=${SMTP_PASS}
      - SMTP_FROM=${SMTP_FROM}
      - SMTP_FROM_NAME=${SMTP_FROM_NAME}
      - CONTACT_EMAIL=${CONTACT_EMAIL}
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
      - GOOGLE_REDIRECT_URI=https://store.abrahem.se/api/auth/google/callback
    volumes:
      - ./public/uploads:/app/public/uploads
    depends_on:
      db:
        condition: service_healthy
    networks:
      - nordic_net

  # MariaDB Database (for App)
  db:
    container_name: nordicstorium-db
    image: mariadb:10.11
    restart: always
    environment:
      MARIADB_DATABASE: ${DB_NAME}
      MARIADB_USER: ${DB_USER}
      MARIADB_PASSWORD: ${DB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
      - ./schemas:/docker-entrypoint-initdb.d
    networks:
      - nordic_net
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect"]
      interval: 10s
      timeout: 5s
      retries: 5

  # PhpMyAdmin (Database GUI)
  phpmyadmin:
    container_name: nordicstorium-phpmyadmin
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    networks:
      - nordic_net
    depends_on:
      db:
        condition: service_healthy

volumes:
  mysql_data:

networks:
  nordic_net:
    driver: bridge
