// DashCaddy Recipe Templates
// Multi-container application stacks deployed as a single unit

const RECIPE_TEMPLATES = {

  // === MEDIA & ENTERTAINMENT ===
  "htpc-suite": {
    name: "HTPC Suite",
    description: "Complete media automation: find, download, organize, and stream",
    icon: "\uD83C\uDFAC",
    category: "Media",
    type: "recipe",
    difficulty: "Intermediate",
    popularity: 98,
    components: [
      {
        id: "prowlarr",
        role: "Indexer Manager",
        templateRef: "prowlarr",
        required: true,
        order: 1
      },
      {
        id: "qbittorrent",
        role: "Download Client",
        templateRef: "qbittorrent",
        required: true,
        order: 2
      },
      {
        id: "sonarr",
        role: "TV Show Manager",
        templateRef: "sonarr",
        required: true,
        order: 3
      },
      {
        id: "radarr",
        role: "Movie Manager",
        templateRef: "radarr",
        required: true,
        order: 4
      },
      {
        id: "lidarr",
        role: "Music Manager",
        templateRef: "lidarr",
        required: false,
        order: 5
      },
      {
        id: "overseerr",
        role: "Request Manager",
        templateRef: "seerr",
        required: false,
        order: 6
      }
    ],
    sharedVolumes: {
      media: {
        label: "Media Library",
        description: "Root folder for all media (movies, TV, music)",
        defaultPath: "/media",
        usedBy: ["sonarr", "radarr", "lidarr", "qbittorrent"]
      },
      downloads: {
        label: "Downloads",
        description: "Shared downloads folder for all download clients",
        defaultPath: "/downloads",
        usedBy: ["sonarr", "radarr", "lidarr", "qbittorrent"]
      }
    },
    autoConnect: {
      enabled: true,
      description: "Automatically connects Sonarr/Radarr to Prowlarr and qBittorrent",
      steps: [
        { action: "configureProwlarrApps", targets: ["sonarr", "radarr", "lidarr"] },
        { action: "configureDownloadClient", client: "qbittorrent", targets: ["sonarr", "radarr", "lidarr"] }
      ]
    },
    setupInstructions: [
      "All services share the same media and downloads folders",
      "Prowlarr is pre-connected to Sonarr, Radarr, and Lidarr",
      "Add indexers in Prowlarr \u2014 they sync automatically to all *arr apps",
      "Add your media library root folders in Sonarr and Radarr",
      "qBittorrent is pre-configured as the download client"
    ]
  },

  // === PRODUCTIVITY ===
  "nextcloud-complete": {
    name: "Nextcloud Complete",
    description: "Full productivity suite: cloud storage, office editing, and collaboration",
    icon: "\u2601\uFE0F",
    category: "Productivity",
    type: "recipe",
    difficulty: "Intermediate",
    popularity: 90,
    components: [
      {
        id: "nextcloud-db",
        role: "Database",
        required: true,
        order: 0,
        docker: {
          image: "mariadb:11",
          ports: [],
          volumes: ["/opt/nextcloud-db/data:/var/lib/mysql"],
          environment: {
            "MYSQL_ROOT_PASSWORD": "{{GENERATED_PASSWORD}}",
            "MYSQL_DATABASE": "nextcloud",
            "MYSQL_USER": "nextcloud",
            "MYSQL_PASSWORD": "{{GENERATED_PASSWORD}}"
          }
        },
        internal: true
      },
      {
        id: "nextcloud-redis",
        role: "Cache",
        required: true,
        order: 0,
        docker: {
          image: "redis:7-alpine",
          ports: [],
          volumes: ["/opt/nextcloud-redis/data:/data"],
          environment: {}
        },
        internal: true
      },
      {
        id: "nextcloud",
        role: "Cloud Platform",
        templateRef: "nextcloud",
        required: true,
        order: 1,
        envOverrides: {
          "MYSQL_HOST": "dashcaddy-nextcloud-db",
          "MYSQL_DATABASE": "nextcloud",
          "MYSQL_USER": "nextcloud",
          "MYSQL_PASSWORD": "{{GENERATED_PASSWORD}}",
          "REDIS_HOST": "dashcaddy-nextcloud-redis"
        }
      },
      {
        id: "collabora",
        role: "Office Suite",
        required: false,
        order: 2,
        docker: {
          image: "collabora/code:latest",
          ports: ["{{PORT}}:9980"],
          volumes: [],
          environment: {
            "aliasgroup1": "https://{{NEXTCLOUD_DOMAIN}}",
            "extra_params": "--o:ssl.enable=false --o:ssl.termination=true"
          }
        },
        subdomain: "office",
        defaultPort: 9980,
        healthCheck: "/"
      }
    ],
    network: {
      name: "dashcaddy-nextcloud",
      driver: "bridge"
    },
    sharedVolumes: {
      data: {
        label: "Cloud Storage",
        description: "Nextcloud data directory for user files",
        defaultPath: "/opt/nextcloud/data",
        usedBy: ["nextcloud"]
      }
    },
    setupInstructions: [
      "Complete the Nextcloud initial setup wizard in the browser",
      "MariaDB and Redis are pre-configured and connected",
      "If Collabora is enabled, configure it in Nextcloud: Settings \u2192 Nextcloud Office",
      "Point Nextcloud Office to your Collabora URL (e.g., https://office.sami)",
      "Configure email, 2FA, and other settings in Nextcloud admin panel"
    ]
  },

  // === DEVELOPMENT ===
  "dev-environment": {
    name: "Dev Environment",
    description: "Self-hosted development workflow: Git, CI/CD, IDE, and database",
    icon: "\uD83D\uDCBB",
    category: "Development",
    type: "recipe",
    difficulty: "Advanced",
    popularity: 82,
    components: [
      {
        id: "dev-postgres",
        role: "Database",
        required: true,
        order: 0,
        docker: {
          image: "postgres:16-alpine",
          ports: [],
          volumes: ["/opt/dev-postgres/data:/var/lib/postgresql/data"],
          environment: {
            "POSTGRES_DB": "gitea",
            "POSTGRES_USER": "gitea",
            "POSTGRES_PASSWORD": "{{GENERATED_PASSWORD}}"
          }
        },
        internal: true
      },
      {
        id: "gitea",
        role: "Git Server",
        templateRef: "gitea",
        required: true,
        order: 1,
        envOverrides: {
          "GITEA__database__DB_TYPE": "postgres",
          "GITEA__database__HOST": "dashcaddy-dev-postgres:5432",
          "GITEA__database__NAME": "gitea",
          "GITEA__database__USER": "gitea",
          "GITEA__database__PASSWD": "{{GENERATED_PASSWORD}}"
        }
      },
      {
        id: "drone",
        role: "CI/CD Pipeline",
        templateRef: "drone",
        required: false,
        order: 2
      },
      {
        id: "vscode-server",
        role: "Web IDE",
        templateRef: "vscode-server",
        required: false,
        order: 3
      }
    ],
    network: {
      name: "dashcaddy-dev",
      driver: "bridge"
    },
    setupInstructions: [
      "Gitea is pre-configured with PostgreSQL database",
      "Complete the Gitea initial setup wizard in the browser",
      "If Drone CI is enabled, connect it to Gitea via OAuth application",
      "VS Code Server provides a full IDE in your browser",
      "All development services share a Docker network for inter-service communication"
    ]
  },

  // === HOME AUTOMATION ===
  "smart-home": {
    name: "Smart Home Hub",
    description: "Home automation: control, automate, and monitor IoT devices",
    icon: "\uD83C\uDFE0",
    category: "Home Automation",
    type: "recipe",
    difficulty: "Intermediate",
    popularity: 88,
    components: [
      {
        id: "mosquitto",
        role: "MQTT Broker",
        required: true,
        order: 0,
        docker: {
          image: "eclipse-mosquitto:2",
          ports: ["1883:1883", "9001:9001"],
          volumes: [
            "/opt/mosquitto/config:/mosquitto/config",
            "/opt/mosquitto/data:/mosquitto/data",
            "/opt/mosquitto/log:/mosquitto/log"
          ],
          environment: {}
        },
        subdomain: "mqtt",
        defaultPort: 1883,
        internal: false,
        setupNote: "MQTT broker for IoT device communication"
      },
      {
        id: "homeassistant",
        role: "Automation Hub",
        templateRef: "homeassistant",
        required: true,
        order: 1
      },
      {
        id: "nodered",
        role: "Flow Automation",
        templateRef: "nodered",
        required: true,
        order: 2
      },
      {
        id: "zigbee2mqtt",
        role: "Zigbee Bridge",
        required: false,
        order: 3,
        docker: {
          image: "koenkk/zigbee2mqtt:latest",
          ports: ["{{PORT}}:8080"],
          volumes: ["/opt/zigbee2mqtt/data:/app/data"],
          environment: {
            "TZ": "{{TIMEZONE}}"
          }
        },
        subdomain: "zigbee",
        defaultPort: 8080,
        healthCheck: "/",
        note: "Requires a Zigbee USB adapter (e.g., Sonoff Zigbee 3.0 USB Dongle Plus)"
      }
    ],
    network: {
      name: "dashcaddy-smarthome",
      driver: "bridge"
    },
    setupInstructions: [
      "Mosquitto MQTT broker is ready for IoT device connections on port 1883",
      "Complete the Home Assistant onboarding wizard in the browser",
      "Connect Home Assistant to MQTT: Settings \u2192 Integrations \u2192 MQTT",
      "Node-RED provides visual flow automation \u2014 connect it to MQTT for device control",
      "If Zigbee2MQTT is enabled, it requires a physical Zigbee USB adapter"
    ]
  }
};

// Recipe category metadata (separate from app categories)
const RECIPE_CATEGORIES = {
  "Media": { icon: "\uD83C\uDFAC", color: "#e74c3c", description: "Media streaming and automation stacks" },
  "Productivity": { icon: "\u2601\uFE0F", color: "#3498db", description: "Cloud storage and office suites" },
  "Development": { icon: "\uD83D\uDCBB", color: "#9b59b6", description: "Self-hosted development environments" },
  "Home Automation": { icon: "\uD83C\uDFE0", color: "#27ae60", description: "IoT and smart home control" }
};

module.exports = { RECIPE_TEMPLATES, RECIPE_CATEGORIES };
