<?php

namespace PloverCRM\Modules\FluentCRM;

use PloverCRM\Core\AbstractModule;

/**
 * FluentCRM Integration Module
 * 
 * Enables FluentCRM as the CRM provider
 */
class FluentCRMModule extends AbstractModule
{
    protected $id = 'fluent_crm';
    protected $dependencies = [];

    /**
     * {@inheritdoc}
     */
    public function getMetadata(): array
    {
        return [
            'name' => 'FluentCRM Integration',
            'description' => 'Use FluentCRM as your CRM provider. Requires FluentCRM plugin to be installed and active.',
            'version' => '1.0.0',
            'author' => 'WebPlover',
            'icon' => '🔌',
            'required' => false,
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function register(): void
    {
        // Register settings tab
        $settingsTab = new Tabs\FluentCRMSettingsTab();
        $settingsTab->register();
    }

    /**
     * {@inheritdoc}
     */
    public function boot(): void
    {
        // Boot logic if needed
    }

    /**
     * {@inheritdoc}
     */
    public function isEnabled(): bool
    {
        // Check if module is disabled
        $disabledModules = get_option('plover_crm_disabled_modules', []);
        return !in_array($this->id, $disabledModules);
    }

    /**
     * Check if FluentCRM plugin is available
     * 
     * @return bool
     */
    public function isFluentCRMAvailable(): bool
    {
        return class_exists('FluentCrm\App\Models\Subscriber') && function_exists('FluentCrmApi');
    }
}
