<?php

namespace App\Modules\Fraud\FraudLabs;

use App\Services\Fraud\Contracts\FraudModuleResponse;

class Response extends FraudModuleResponse
{
    /**
     * FraudLabs Pro error codes that indicate failure
     *
     * Error codes:
     * 101 - Missing required parameters
     * 102 - Invalid license key
     * 103 - Insufficient credits
     * 104 - Account suspended
     * 203 - Database error
     * 204 - Service unavailable
     * 210 - Invalid IP address
     * 211 - Invalid email address
     */
    protected array $failureErrorCodes = [101, 102, 103, 104, 203, 204, 210, 211];

    /**
     * Override isSuccessful to check FraudLabs-specific error codes
     */
    public function isSuccessful(): bool
    {
        $errorCode = $this->get('fraudlabspro_error_code');

        return $this->httpCode === 200 &&
               (!$errorCode || !in_array($errorCode, $this->failureErrorCodes));
    }
}
