<?php

namespace CheckoutWC;

require_once __DIR__ . '/../src/ClientBuilder.php';
require_once __DIR__ . '/../src/US_ZIPCode/Lookup.php';
require_once __DIR__ . '/../src/US_ZIPCode/Result.php';
require_once __DIR__ . '/../src/BasicAuthCredentials.php';
// require_once(__DIR__ . '/../src/SharedCredentials.php');
use CheckoutWC\SmartyStreets\PhpSdk\Exceptions\SmartyException;
use CheckoutWC\SmartyStreets\PhpSdk\BasicAuthCredentials;
// use SmartyStreets\PhpSdk\SharedCredentials;
use CheckoutWC\SmartyStreets\PhpSdk\US_ZIPCode\Lookup;
use CheckoutWC\SmartyStreets\PhpSdk\ClientBuilder;
$lookupExample = new UsZIPCodeSingleLookupExample();
$lookupExample->run();
class UsZIPCodeSingleLookupExample
{
    public function run()
    {
        // $authId = 'Your SmartyStreets Auth ID here';
        // $authToken = 'Your SmartyStreets Auth Token here';
        // We recommend storing your secret keys in environment variables instead---it's safer!
        $authId = \getenv('SMARTY_AUTH_ID');
        $authToken = \getenv('SMARTY_AUTH_TOKEN');
        // For client-side requests (browser/mobile), use SharedCredentials:
        // $credentials = new SharedCredentials($key, $hostname);
        $credentials = new BasicAuthCredentials($authId, $authToken);
        $client = (new ClientBuilder($credentials))->buildUsZIPCodeApiClient();
        // Documentation for input fields can be found at:
        // https://smartystreets.com/docs/cloud/us-zipcode-api
        $lookup = new Lookup();
        $lookup->setInputId("dfc33cb6-829e-4fea-aa1b-b6d6580f0817");
        // Optional ID from you system
        $lookup->setCity("Mountain View");
        $lookup->setState("California");
        // Uncomment the below line to add a custom parameter to the API call
        // $lookup->addCustomParameter("parameter", "value");
        try {
            $client->sendLookup($lookup);
            $this->displayResults($lookup);
        } catch (\Exception $ex) {
            echo $ex->getMessage();
        }
    }
    public function displayResults(Lookup $lookup)
    {
        $result = $lookup->getResult();
        $zipCodes = $result->getZIPCodes();
        $cities = $result->getCities();
        foreach ($cities as $city) {
            echo "\nCity: " . $city->getCity();
            echo "\nState: " . $city->getState();
            echo "\nMailable City: " . \json_encode($city->getMailableCity());
        }
        foreach ($zipCodes as $zip) {
            echo "\n\nZIP Code: " . $zip->getZIPCode();
            echo "\nLatitude: " . $zip->getLatitude();
            echo "\nLongitude: " . $zip->getLongitude();
        }
    }
}
