<?php

declare(strict_types=1);

use App\CiotAPI;

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'CiotAPI.php';

$config = require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'ciot.php';

$ciotApi = new CiotAPI([
    'environment' => $config['environment'],
    'provider_token' => $config['provider_token'],
    'homologation_url' => $config['homologation_url'],
    'production_url' => $config['production_url'],
    'timeout' => $config['timeout'],
    'connect_timeout' => $config['connect_timeout'],
    'log_file' => $config['log_file'],
    'client_certificate_path' => $config['client_certificate_path'],
    'client_certificate_password' => $config['client_certificate_password'],
    'client_certificate_type' => $config['client_certificate_type'],
]);

$operationData = [
    'cpf_motorista' => '529.982.247-25',
    'nome_motorista' => 'Joao da Silva',
    'placa_veiculo' => 'ABC1D23',
    'rntrc' => '12345678',
    'valor_frete' => 2500.75,
    'origem' => [
        'cidade' => 'Sao Paulo',
        'uf' => 'SP',
    ],
    'destino' => [
        'cidade' => 'Curitiba',
        'uf' => 'PR',
    ],
    'mdfe' => [
        'chave' => null,
        'numero' => null,
    ],
    'cte' => [
        'chave' => null,
        'numero' => null,
    ],
    'referencia_externa' => 'PEDIDO-12345',
];

$response = $ciotApi->emitirCiot($operationData);

echo json_encode($response, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL;
