<?php
namespace EasyChat\Library\Messenger;

 
final class SmsDispatchAcceptancePolicy {
    public static function decide(array $result, bool $recovery_active): array {
        if (!empty($result['success'])) {
            return ['accepted' => true, 'dispatch_pending' => false, 'delivery' => $result];
        }
        if (!empty($result['terminal']) || !$recovery_active) {
            return ['accepted' => false, 'dispatch_pending' => false, 'delivery' => $result];
        }

        return [
            'accepted' => true,
            'dispatch_pending' => true,
            'delivery' => [
                'success' => true,
                'http_code' => 202,
                'provider' => 'sms',
                'status' => 'queued',
                'code' => 'sms_dispatch_pending',
                'retryable' => 1,
                'retry_scheduled' => 1,
            ],
        ];
    }
}
