<?php
namespace EasyChat\Library\Messenger;








class SmsProvider implements MessengerProviderInterface {
    const PROVIDER = 'sms';

    private $registry;

    public function __construct($registry = null) {
        $this->registry = $registry;
    }

    public function providerCode(): string {
        return self::PROVIDER;
    }

    public function getBotInfo(string $token): array {
        return ['success' => true, 'name' => 'SMS'];
    }

    public function syncWebhook(array $channel, string $token, string $webhook_url, string $secret): array {
        return ['success' => true, 'skipped' => 'local_android_sms'];
    }

    public function parseWebhook(array $payload): array {
        return $payload;
    }

    public function sendMessage(string $token, string $external_user_id, string $text, array $attachments = [], array $options = []): array {
        if (trim($text) === '') {
            return ['success' => false, 'error' => 'sms_text_empty'];
        }
        if ($attachments) {
            return ['success' => false, 'error' => 'sms_attachments_unsupported'];
        }

        $service = new SmsOutboundService($this->registry);
        return $service->enqueueSms([
            'phone' => $external_user_id,
            'text' => $text,
            'chat_id' => (int)($options['chat_id'] ?? 0),
            'message_id' => (int)($options['message_id'] ?? 0),
            'delivery_id' => (int)($options['delivery_id'] ?? 0),
            'manager_id' => (int)($options['manager_id'] ?? 0),
            'expires_at' => (string)($options['expires_at'] ?? ''),
        ]);
    }
}
