"""
Configuration for {{ project_name }}
Generated by ABI-Core scaffolding
"""

import os
from typing import Dict, Any

class {{ project_name.title().replace('_', '').replace('-', '').replace(' ', '') }}Config:
    """Configuration class for {{ project_name }}"""
    
    def __init__(self):
        # Basic project settings
        self.project_name = "{{ project_name }}"
        self.version = "{{ version | default('0.1.0') }}"
        self.description = "{{ description | default('ABI-powered project') }}"
        
        # ABI Core settings
        self.abi_role = os.getenv('ABI_ROLE', '{{ abi_role | default('ABI Project') }}')
        self.abi_node = os.getenv('ABI_NODE', '{{ abi_node | default('ABI Node') }}')
        
        # Agent settings
        self.agent_host = os.getenv('AGENT_HOST', '{{ agent_host | default("0.0.0.0") }}')
        self.agent_port = int(os.getenv('AGENT_PORT', '{{ agent_port | default("8000") }}'))
        self.agent_base = os.getenv('AGENT_BASE', f'http://{self.agent_host}:{self.agent_port}')
        
        # Model settings
        self.model_name = os.getenv('MODEL_NAME', '{{ model_name | default("qwen2.5:3b") }}')
        self.ollama_host = os.getenv('OLLAMA_HOST', '{{ ollama_host | default("http://localhost:11434") }}')
        
        # Security settings
        self.enable_guardial = {{ enable_guardial | default(True) }}
        self.opa_host = os.getenv('OPA_HOST', '{{ opa_host | default("localhost") }}')
        self.opa_port = int(os.getenv('OPA_PORT', '{{ opa_port | default("8181") }}'))
        
        # Semantic layer settings
        {% if with_semantic_layer %}
        self.semantic_layer_host = os.getenv('SEMANTIC_LAYER_HOST', '{{ semantic_layer_host | default("localhost") }}')
        self.semantic_layer_port = int(os.getenv('SEMANTIC_LAYER_PORT', '{{ semantic_layer_port | default("10100") }}'))
        self.weaviate_url = os.getenv('WEAVIATE_URL', '{{ weaviate_url | default("http://localhost:8080") }}')
        self.embedding_model = os.getenv('EMBEDDING_MODEL', '{{ embedding_model | default("nomic-embed-text:v1.5") }}')
        self.agent_cards_dir = os.getenv('AGENT_CARDS_DIR', '{{ agent_cards_dir | default("./services/semantic_layer/mcp_server/agent_cards") }}')
        {% endif %}
        
        # Guardian security settings
        {% if with_guardian %}
        self.guardian_host = os.getenv('GUARDIAN_HOST', '{{ guardian_host | default("localhost") }}')
        self.guardian_port = int(os.getenv('GUARDIAN_PORT', '{{ guardian_port | default("11438") }}'))
        self.max_risk_threshold = float(os.getenv('MAX_RISK_THRESHOLD', '{{ max_risk_threshold | default("0.7") }}'))
        self.emergency_log_dir = os.getenv('EMERGENCY_LOG_DIR', '{{ emergency_log_dir | default("./logs/emergency") }}')
        {% endif %}
        
        # Domain-specific settings
        self.domain = "{{ domain }}"
        {% if domain == 'finance' %}
        self.compliance_required = {{ compliance_required | default(True) }}
        self.audit_all_transactions = {{ audit_all_transactions | default(True) }}
        self.max_transaction_amount = float(os.getenv('MAX_TRANSACTION_AMOUNT', '{{ max_transaction_amount | default("10000.0") }}'))
        {% elif domain == 'healthcare' %}
        self.hipaa_compliance = {{ hipaa_compliance | default(True) }}
        self.phi_protection = {{ phi_protection | default(True) }}
        self.audit_patient_access = {{ audit_patient_access | default(True) }}
        {% endif %}
        
        # Logging settings
        self.log_level = os.getenv('LOG_LEVEL', '{{ log_level | default("INFO") }}')
        self.debug = os.getenv('DEBUG', '{{ debug | default("False") }}').lower() == 'true'
    
    def to_dict(self) -> Dict[str, Any]:
        """Convert config to dictionary"""
        return {
            'project_name': self.project_name,
            'version': self.version,
            'description': self.description,
            'abi_role': self.abi_role,
            'abi_node': self.abi_node,
            'agent_host': self.agent_host,
            'agent_port': self.agent_port,
            'agent_base': self.agent_base,
            'model_name': self.model_name,
            'ollama_host': self.ollama_host,
            'enable_guardial': self.enable_guardial,
            'opa_host': self.opa_host,
            'opa_port': self.opa_port,
            {% if with_semantic_layer %}
            'semantic_layer_host': self.semantic_layer_host,
            'semantic_layer_port': self.semantic_layer_port,
            'weaviate_url': self.weaviate_url,
            'embedding_model': self.embedding_model,
            'agent_cards_dir': self.agent_cards_dir,
            {% endif %}
            {% if with_guardian %}
            'guardian_host': self.guardian_host,
            'guardian_port': self.guardian_port,
            'max_risk_threshold': self.max_risk_threshold,
            'emergency_log_dir': self.emergency_log_dir,
            {% endif %}
            'domain': self.domain,
            {% if domain == 'finance' %}
            'compliance_required': self.compliance_required,
            'audit_all_transactions': self.audit_all_transactions,
            'max_transaction_amount': self.max_transaction_amount,
            {% elif domain == 'healthcare' %}
            'hipaa_compliance': self.hipaa_compliance,
            'phi_protection': self.phi_protection,
            'audit_patient_access': self.audit_patient_access,
            {% endif %}
            'log_level': self.log_level,
            'debug': self.debug
        }

# Global config instance
config = {{ project_name.title().replace('_', '').replace('-', '').replace(' ', '') }}Config()