version: '3.8'

services:
  postgres:
    image: postgres:16-alpine
    container_name: replymind-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: replymind
      POSTGRES_PASSWORD: replymind_secret
      POSTGRES_DB: replymind_ai
    ports:
      - '5432:5432'
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U replymind']
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: .
      target: development
    container_name: replymind-backend
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - '4000:4000'
    environment:
      NODE_ENV: development
      PORT: 4000
      DATABASE_URL: postgresql://replymind:replymind_secret@postgres:5432/replymind_ai?schema=public
      JWT_SECRET: dev-jwt-secret-change-in-production
      GEMINI_API_KEY: ${GEMINI_API_KEY}
      FACEBOOK_APP_ID: ${FACEBOOK_APP_ID}
      FACEBOOK_APP_SECRET: ${FACEBOOK_APP_SECRET}
      FACEBOOK_PAGE_ACCESS_TOKEN: ${FACEBOOK_PAGE_ACCESS_TOKEN}
      FACEBOOK_WEBHOOK_VERIFY_TOKEN: ${FACEBOOK_WEBHOOK_VERIFY_TOKEN}
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
      STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
      FRONTEND_URL: http://localhost:3000
    volumes:
      - ./backend/src:/app/backend/src
      - ./backend/prisma:/app/backend/prisma
    command: sh -c "npx prisma generate && npx prisma db push && npm run dev"

  frontend:
    build:
      context: .
      target: development
    container_name: replymind-frontend
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - '3000:3000'
    environment:
      NODE_ENV: development
      NEXT_PUBLIC_API_URL: http://localhost:4000/api/v1
      NEXTAUTH_URL: http://localhost:3000
      NEXTAUTH_SECRET: dev-nextauth-secret-change-in-production
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      FACEBOOK_CLIENT_ID: ${FACEBOOK_CLIENT_ID}
      FACEBOOK_CLIENT_SECRET: ${FACEBOOK_CLIENT_SECRET}
    volumes:
      - ./frontend/src:/app/frontend/src
      - ./frontend/public:/app/frontend/public
    command: npm run dev

volumes:
  postgres_data: