# Lidify Full Stack - Production Deployment
# Uses pre-built Lidify image from DockerHub + all external services
#
# Usage:
#   docker compose -f docker-compose.server.yml up -d

services:
    # ==============================================================================
    # LIDIFY (All-in-One: Frontend + Backend + PostgreSQL + Redis)
    # ==============================================================================

    lidify:
        image: chevron7locked/lidify:latest
        container_name: lidify
        ports:
            - "${FRONTEND_PORT:-3030}:3030"
        volumes:
            # IMPORTANT: CHANGE THIS to your music library path
            - ${MUSIC_PATH:-/path/to/your/music}:/music
            # Persistent data (database, cache, covers, etc.)
            - lidify_data:/data
        environment:
            - TZ=${TZ:-America/Chicago}
            # Generate with: openssl rand -base64 32
            - SESSION_SECRET=${SESSION_SECRET:-changeme-generate-secure-key}
            # Lidarr webhook callback URL - how Lidarr reaches Lidify when downloads complete
            # Default uses host.docker.internal which works on most setups with extra_hosts below
            # Override if using custom Docker networks: e.g., http://192.168.0.20:3030
            - LIDIFY_CALLBACK_URL=${LIDIFY_CALLBACK_URL:-http://host.docker.internal:3030}
        # Makes host.docker.internal work on Linux (already works on Docker Desktop)
        extra_hosts:
            - "host.docker.internal:host-gateway"
        restart: unless-stopped
        healthcheck:
            test:
                [
                    "CMD",
                    "wget",
                    "--no-verbose",
                    "--tries=1",
                    "--spider",
                    "http://localhost:3030",
                ]
            interval: 30s
            timeout: 10s
            retries: 3

    # ==============================================================================
    # EXTERNAL SERVICES (Music Management)
    # ==============================================================================

    # Lidarr - Music collection manager
    lidarr:
        image: lscr.io/linuxserver/lidarr:latest
        container_name: lidify_lidarr
        environment:
            - PUID=${PUID:-1000}
            - PGID=${PGID:-1000}
            - TZ=${TZ:-UTC}
        volumes:
            - lidarr_config:/config
            - ${MUSIC_PATH:-./music}:/music
            - ${DOWNLOAD_PATH:-./downloads}:/downloads
        ports:
            - "8686:8686"
        restart: unless-stopped

    # Prowlarr - Indexer manager
    prowlarr:
        image: lscr.io/linuxserver/prowlarr:latest
        container_name: lidify_prowlarr
        environment:
            - PUID=${PUID:-1000}
            - PGID=${PGID:-1000}
            - TZ=${TZ:-UTC}
        volumes:
            - prowlarr_config:/config
        ports:
            - "9696:9696"
        restart: unless-stopped

    # FlareSolverr - Cloudflare bypass for Prowlarr
    flaresolverr:
        image: ghcr.io/flaresolverr/flaresolverr:latest
        container_name: lidify_flaresolverr
        environment:
            - LOG_LEVEL=${LOG_LEVEL:-info}
            - LOG_HTML=${LOG_HTML:-false}
            - CAPTCHA_SOLVER=${CAPTCHA_SOLVER:-none}
            - TZ=${TZ:-UTC}
        ports:
            - "8191:8191"
        restart: unless-stopped

    # Slskd - Soulseek client
    slskd:
        image: slskd/slskd:latest
        container_name: lidify_slskd
        environment:
            - TZ=${TZ:-UTC}
            - SLSKD_REMOTE_CONFIGURATION=true
            - SLSKD_SOULSEEK_USERNAME=${SLSKD_SOULSEEK_USERNAME:-}
            - SLSKD_SOULSEEK_PASSWORD=${SLSKD_SOULSEEK_PASSWORD:-}
        ports:
            - "5030:5030" # Web UI
            - "5031:5031" # File server
        volumes:
            - slskd_config:/app
            - ${MUSIC_PATH:-./music}:/music
            - ${MUSIC_PATH:-./music}/Soulseek:/downloads
        restart: unless-stopped

    # Soularr - Lidarr + Soulseek integration
    soularr:
        image: mrusse08/soularr:latest
        container_name: lidify_soularr
        user: "${PUID:-1000}:${PGID:-1000}"
        environment:
            - TZ=${TZ:-UTC}
            - SCRIPT_INTERVAL=300
        volumes:
            - ${MUSIC_PATH:-./music}/Soulseek:/downloads
            - soularr_data:/data
        restart: unless-stopped
        depends_on:
            - slskd
            - lidarr

    # qBittorrent - Torrent client
    qbittorrent:
        image: lscr.io/linuxserver/qbittorrent:latest
        container_name: lidify_qbittorrent
        environment:
            - PUID=${PUID:-1000}
            - PGID=${PGID:-1000}
            - TZ=${TZ:-UTC}
            - WEBUI_PORT=8080
        volumes:
            - qbittorrent_config:/config
            - ${MUSIC_PATH:-./music}/torrents:/music/torrents
            - ${DOWNLOAD_PATH:-./downloads}:/downloads
        ports:
            - "8080:8080"
            - "6881:6881"
            - "6881:6881/udp"
        restart: unless-stopped

    # NZBGet - Usenet client
    nzbget:
        image: lscr.io/linuxserver/nzbget:latest
        container_name: lidify_nzbget
        environment:
            - PUID=${PUID:-1000}
            - PGID=${PGID:-1000}
            - TZ=${TZ:-UTC}
        volumes:
            - nzbget_config:/config
            - ${MUSIC_PATH:-./music}/usenet:/music/usenet
            - ${DOWNLOAD_PATH:-./downloads}:/downloads
        ports:
            - "6789:6789"
        restart: unless-stopped

volumes:
    # Lidify
    lidify_data:
    # External services
    lidarr_config:
    prowlarr_config:
    slskd_config:
    soularr_data:
    qbittorrent_config:
    nzbget_config:

networks:
    default:
        name: lidify_network
