/**
 * Descomplicar® Crescimento Digital
 * https://descomplicar.pt
 */

<?php

/**
 * Desk-Moloni Module Configuration
 * 
 * This file contains the module configuration that will be loaded by CodeIgniter
 * 
 * @package DeskMoloni\Config
 * @version 3.0
 */

defined('BASEPATH') or exit('No direct script access allowed');

// Application constants - with proper checks to avoid redefinition
if (!defined('APP_MINIMUM_REQUIRED_PHP_VERSION')) {
    define('APP_MINIMUM_REQUIRED_PHP_VERSION', '8.4.0');
}

if (!defined('DESK_MOLONI_VERSION')) {
    define('DESK_MOLONI_VERSION', '3.0.1');
}

if (!defined('DESK_MOLONI_API_VERSION')) {
    define('DESK_MOLONI_API_VERSION', '1');
}

if (!defined('DESK_MOLONI_MIN_PERFEX_VERSION')) {
    define('DESK_MOLONI_MIN_PERFEX_VERSION', '3.0.0');
}

// Module configuration array
$config['desk_moloni'] = [
    'module_name' => 'Desk-Moloni Integration',
    'version' => '3.0.1',
    'description' => 'Complete bidirectional synchronization between Perfex CRM and Moloni ERP',
    'requires_perfex_version' => '3.0.0',
    'requires_php_version' => '8.4.0',
    'author' => 'Descomplicar.pt',
    'author_uri' => 'https://descomplicar.pt',
    'module_uri' => 'https://descomplicar.pt/desk-moloni'
];

// API Configuration
$config['desk_moloni_api'] = [
    'base_url' => 'https://api.moloni.pt/v1/',
    'oauth_url' => 'https://www.moloni.pt/v1/',
    'timeout' => 30,
    'max_retries' => 3,
    'user_agent' => 'Desk-Moloni-Integration/3.0.1',
    'rate_limit' => [
        'requests_per_minute' => 60,
        'window_size' => 60
    ]
];

// Default sync settings
$config['desk_moloni_sync'] = [
    'auto_sync_enabled' => true,
    'realtime_sync_enabled' => false,
    'batch_sync_enabled' => true,
    'sync_delay' => 300,
    'batch_size' => 10,
    'max_attempts' => 3,
    'retry_delay' => 300
];

// Entity sync configuration
$config['desk_moloni_entities'] = [
    'customers' => [
        'enabled' => true,
        'auto_sync' => true,
        'direction' => 'bidirectional' // perfex_to_moloni, moloni_to_perfex, bidirectional
    ],
    'invoices' => [
        'enabled' => true,
        'auto_sync' => true,
        'direction' => 'bidirectional'
    ],
    'estimates' => [
        'enabled' => true,
        'auto_sync' => true,
        'direction' => 'bidirectional'
    ],
    'credit_notes' => [
        'enabled' => true,
        'auto_sync' => true,
        'direction' => 'bidirectional'
    ],
    'products' => [
        'enabled' => false,
        'auto_sync' => false,
        'direction' => 'bidirectional'
    ],
    'receipts' => [
        'enabled' => false,
        'auto_sync' => false,
        'direction' => 'bidirectional'
    ]
];

// Security settings
$config['desk_moloni_security'] = [
    'encryption_enabled' => true,
    'webhook_signature_verification' => true,
    'audit_logging_enabled' => true,
    'encryption_algorithm' => 'AES-256-GCM'
];

// Performance settings
$config['desk_moloni_performance'] = [
    'monitoring_enabled' => true,
    'caching_enabled' => true,
    'cache_ttl' => 3600,
    'log_slow_queries' => true,
    'slow_query_threshold' => 1000
];

// Logging configuration
$config['desk_moloni_logging'] = [
    'enabled' => true,
    'level' => 'info', // debug, info, warning, error
    'log_api_requests' => false,
    'retention_days' => 30,
    'max_file_size' => '10MB'
];

// Queue settings
$config['desk_moloni_queue'] = [
    'enabled' => true,
    'batch_size' => 10,
    'max_attempts' => 3,
    'retry_delay' => 300,
    'processing_timeout' => 300
];

// Webhook settings
$config['desk_moloni_webhooks'] = [
    'enabled' => true,
    'timeout' => 30,
    'max_retries' => 3,
    'verify_signature' => true
];

// Client portal settings
$config['desk_moloni_client_portal'] = [
    'enabled' => false,
    'allow_pdf_download' => true,
    'show_sync_status' => true,
    'show_moloni_links' => false
];

// Error handling
$config['desk_moloni_error_handling'] = [
    'continue_on_error' => true,
    'max_consecutive_errors' => 5,
    'enable_notifications' => true,
    'notification_email' => '',
    'notification_methods' => ['email', 'log']
];

// Development settings
$config['desk_moloni_development'] = [
    'debug_mode' => false,
    'test_mode' => false,
    'mock_api_responses' => false,
    'verbose_logging' => false
];