# Proxmox VE Configuration for DBIS Core Banking System
# This configuration extends the main proxmox.conf with DBIS Core-specific settings

# Source the main Proxmox configuration
if [[ -f "$(dirname "${BASH_SOURCE[0]:-.}")/../../smom-dbis-138-proxmox/config/proxmox.conf" ]]; then
    source "$(dirname "${BASH_SOURCE[0]:-.}")/../../smom-dbis-138-proxmox/config/proxmox.conf" 2>/dev/null || true
fi

# DBIS Core Project Configuration
DBIS_CORE_PROJECT_NAME="dbis-core"
DBIS_CORE_PROJECT_ROOT="/opt/dbis-core"
DBIS_CORE_DEPLOYMENT_USER="dbis"
DBIS_CORE_DEPLOYMENT_GROUP="dbis"

# VMID Ranges for DBIS Core Services
# Using Sovereign Cloud Band range: 10000-13999
VMID_DBIS_CORE_START=10000              # DBIS Core Services: 10000-10099 (100 VMIDs)
VMID_DBIS_DB_START=10100                # Database: 10100-10119 (20 VMIDs)
VMID_DBIS_CACHE_START=10120             # Cache: 10120-10129 (10 VMIDs)
VMID_DBIS_FRONTEND_START=10130          # Frontend: 10130-10149 (20 VMIDs)
VMID_DBIS_API_START=10150               # API: 10150-10199 (50 VMIDs)
VMID_DBIS_EXPANSION_START=10200         # Expansion: 10200-13999 (3,800 VMIDs)

# Initial Deployment VMIDs
VMID_DBIS_POSTGRES_PRIMARY=10100
VMID_DBIS_POSTGRES_REPLICA=10101
VMID_DBIS_REDIS=10120
VMID_DBIS_API_PRIMARY=10150
VMID_DBIS_API_SECONDARY=10151
VMID_DBIS_FRONTEND=10130

# Resource Specifications

# PostgreSQL Database Containers
DBIS_POSTGRES_MEMORY="8192"             # 8 GB
DBIS_POSTGRES_CORES="4"
DBIS_POSTGRES_DISK="200"                # GB
DBIS_POSTGRES_DISK_EXPANDABLE="true"
DBIS_POSTGRES_SWAP="1024"                # 1 GB

# Redis Cache Container
DBIS_REDIS_MEMORY="4096"                # 4 GB
DBIS_REDIS_CORES="2"
DBIS_REDIS_DISK="50"                    # GB
DBIS_REDIS_DISK_EXPANDABLE="true"
DBIS_REDIS_SWAP="512"                   # 512 MB

# Backend API Containers
DBIS_API_MEMORY="8192"                  # 8 GB
DBIS_API_CORES="4"
DBIS_API_DISK="100"                     # GB
DBIS_API_DISK_EXPANDABLE="true"
DBIS_API_SWAP="1024"                    # 1 GB

# Frontend Admin Console Container
DBIS_FRONTEND_MEMORY="4096"             # 4 GB
DBIS_FRONTEND_CORES="2"
DBIS_FRONTEND_DISK="50"                 # GB
DBIS_FRONTEND_DISK_EXPANDABLE="true"
DBIS_FRONTEND_SWAP="512"                # 512 MB

# Network Configuration
DBIS_NETWORK_BRIDGE="${PROXMOX_BRIDGE:-vmbr0}"

# IP Address Allocation
# Note: Database IPs adjusted to avoid conflicts with blockchain validators (192.168.11.100-104)
DBIS_DB_IP_START="192.168.11.105"       # Database range: 192.168.11.105-119 (adjusted from .100)
DBIS_CACHE_IP_START="192.168.11.120"    # Cache range: 192.168.11.120-129
DBIS_FRONTEND_IP_START="192.168.11.130" # Frontend range: 192.168.11.130-149
# Note: API IPs adjusted to avoid conflicts with blockchain sentries (192.168.11.150-154)
DBIS_API_IP_START="192.168.11.155"      # API range: 192.168.11.155-199 (adjusted from .150)

# Specific IP Addresses for Initial Deployment
DBIS_POSTGRES_PRIMARY_IP="192.168.11.105"  # Updated from 192.168.11.100 (conflict resolved)
DBIS_POSTGRES_REPLICA_IP="192.168.11.106"  # Updated from 192.168.11.101 (conflict resolved)
DBIS_REDIS_IP="192.168.11.120"
DBIS_API_PRIMARY_IP="192.168.11.155"       # Updated from 192.168.11.150 (conflict resolved)
DBIS_API_SECONDARY_IP="192.168.11.156"     # Updated from 192.168.11.151 (conflict resolved)
DBIS_FRONTEND_IP="192.168.11.130"

# Container Base Configuration
DBIS_CONTAINER_OS_TEMPLATE="${CONTAINER_OS_TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}"
DBIS_CONTAINER_UNPRIVILEGED="1"         # Use unprivileged containers
DBIS_CONTAINER_ONBOOT="1"               # Start on boot
DBIS_CONTAINER_TIMEZONE="${CONTAINER_TIMEZONE:-America/Los_Angeles}"

# Node.js Version
DBIS_NODE_VERSION="18"                  # Node.js 18+ required

# PostgreSQL Version
DBIS_POSTGRES_VERSION="15"              # PostgreSQL 15 recommended

# Redis Version
DBIS_REDIS_VERSION="7"                  # Redis 7 recommended

# Service Counts
DBIS_POSTGRES_COUNT=1                   # Primary database (replica optional)
DBIS_POSTGRES_REPLICA_COUNT=0           # Set to 1 to enable replica
DBIS_REDIS_COUNT=1
DBIS_API_COUNT=2                        # Primary + Secondary for HA
DBIS_FRONTEND_COUNT=1

# Deployment Configuration
DBIS_DEPLOYMENT_ENV="${DBIS_DEPLOYMENT_ENV:-production}"
DBIS_ENABLE_HA="${DBIS_ENABLE_HA:-true}" # High Availability mode

# Database Configuration
DBIS_DB_NAME="dbis_core"
DBIS_DB_USER="dbis"
DBIS_DB_PASSWORD=""                     # Set via environment or secrets management

# API Configuration
DBIS_API_PORT="3000"
DBIS_API_WORKERS="${DBIS_API_WORKERS:-4}" # Number of worker processes

# Frontend Configuration
DBIS_FRONTEND_PORT="80"
DBIS_FRONTEND_HTTPS_PORT="443"

# Logging
DBIS_LOG_DIR="/var/log/dbis-core"
DBIS_LOG_LEVEL="${LOG_LEVEL:-INFO}"

# Debug Mode
DBIS_DEBUG="${DEBUG:-0}"

# Parallel Deployment Configuration
DBIS_PARALLEL_DEPLOY="${PARALLEL_DEPLOY:-true}"
DBIS_MAX_PARALLEL="${MAX_PARALLEL:-5}"  # Conservative limit for DBIS services

# Service-specific parallel limits
DBIS_MAX_PARALLEL_DB="${DBIS_MAX_PARALLEL_DB:-2}"      # Database operations
DBIS_MAX_PARALLEL_API="${DBIS_MAX_PARALLEL_API:-3}"    # API deployment
DBIS_MAX_PARALLEL_FRONTEND="${DBIS_MAX_PARALLEL_FRONTEND:-2}" # Frontend deployment

