<?php

namespace FedexRest\Tests\LocationSearch;

use FedexRest\Authorization\Authorize;
use FedexRest\Entity\Address;
use FedexRest\Services\LocationSearch\FindLocations;
use FedexRest\Services\LocationSearch\Type\SearchCriterionType;
use PHPUnit\Framework\TestCase;

class FindLocationsTest extends TestCase
{
    protected Authorize $auth;

    protected function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $this->auth = (new Authorize)
            ->setClientId('l7749d031872cf4b55a7889376f360d045')
            ->setClientSecret('bd59d91084e8482895d4ae2fb4fb79a3');
    }

    public function testSearch()
    {
        $locate = (new FindLocations)
            ->setSearchCriterion(SearchCriterionType::_ADDRESS)
            ->setAddress(
                (new Address)
                    ->setCountryCode('US')
                    ->setPostalCode('90210')
                    ->setStateOrProvince('CA')
                    ->setCity('Beverly Hills')
            )
            ->setAccessToken($this->auth->authorize()->access_token)
            ->request();

        $this->assertObjectHasProperty('transactionId', $locate);
    }

    public function testSearchWithResultLimit()
    {
        $locate = (new FindLocations)
            ->setSearchCriterion(SearchCriterionType::_ADDRESS)
            ->setAddress(
                (new Address)
                    ->setCountryCode('US')
                    ->setPostalCode('90210')
                    ->setStateOrProvince('CA')
                    ->setCity('Beverly Hills')
            )
            ->setAccessToken($this->auth->authorize()->access_token)
            ->setResultLimit(3)
            ->request();

        $this->assertCount(3, $locate->output->locationDetailList);
    }
}
