version: "3.8"

services:
  mysql:
    image: mysql:8.0
    container_name: msp_mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-rootpass}
      MYSQL_DATABASE: it_servis_rmm
      TZ: Europe/Istanbul
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    ports:
      - "${DB_PORT:-3306}:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./server/sql/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p${DB_PASSWORD:-rootpass}"]
      interval: 10s
      timeout: 5s
      retries: 10

  api:
    build: ./server
    container_name: msp_api
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      PORT: 4000
      NODE_ENV: production
      DB_HOST: mysql
      DB_PORT: 3306
      DB_USER: root
      DB_PASSWORD: ${DB_PASSWORD:-rootpass}
      DB_NAME: it_servis_rmm
      JWT_SECRET: ${JWT_SECRET:-degistir-bunu-uzun-ve-guvenli-bir-anahtar}
      CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost:5173}
    ports:
      - "4000:4000"

  web:
    build: ./frontend
    container_name: msp_web
    restart: unless-stopped
    depends_on:
      - api
    environment:
      VITE_API_URL: http://localhost:4000
    ports:
      - "5173:5173"

volumes:
  mysql_data:
