<?php

use App\Services\AuthorizeNetPaymentService;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;

Artisan::command('inspire', function () {
    $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');

Artisan::command('authorizenet:test', function (AuthorizeNetPaymentService $anet) {
    $sandbox = filter_var(config('authorize.sandbox'), FILTER_VALIDATE_BOOLEAN);
    $endpoint = $sandbox ? 'https://apitest.authorize.net (SANDBOX — keys must be from sandbox.authorize.net)' : 'https://api2.authorize.net (LIVE — keys must be from account.authorize.net)';
    $this->line('Endpoint: '.$endpoint);
    $this->info('Testing API Login ID + Transaction Key (authenticateTest)…');
    $result = $anet->testApiCredentials();
    if ($result['ok']) {
        $this->info($result['message']);
    } else {
        $this->error($result['message']);
        $this->line('Fix: use credentials from the same merchant account. Sandbox: sandbox.authorize.net → API Credentials. Match AUTHORIZENET_SANDBOX (true = sandbox keys only).');
    }

    return $result['ok'] ? 0 : 1;
})->purpose('Verify Authorize.Net API Login ID and Transaction Key (no payment)');
