<?php

require_once __DIR__ . '/vendor/autoload.php';

use SmsNotifier\Service\Logger;
use SmsNotifier\Service\OptionsManager;
use SmsNotifier\Service\PluginDataValidator;
use SmsNotifier\Factory\NotificationDataFactory;
use SmsNotifier\Facade\PluginNotifierFacade;
use Ubnt\UcrmPluginSdk\Service\UcrmApi;
use Ubnt\UcrmPluginSdk\Service\PluginConfigManager;
use GuzzleHttp\Client;

$config = PluginConfigManager::create()->loadConfig();
$ipServer = $config['ipserver'] ?? 'localhost';
$apiUrl = "https://$ipServer/crm/api/v1.0/";
$token = $config['apitoken'] ?? '';

$client = new Client([
    'base_uri' => $apiUrl,
    'verify' => false,
]);

$ucrmApi = new UcrmApi($client, $token);

try {
    echo "Fecthing custom attributes from $apiUrl\n";
    $attributes = $ucrmApi->get('custom-attributes', ['attributeType' => 'client']);
    echo "Total attributes: " . count($attributes) . "\n";
    foreach ($attributes as $attr) {
        echo sprintf("ID: %s | Name: %s | Key: %s\n", $attr['id'], $attr['name'], $attr['key']);
    }
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
