<?php

namespace MessageBird\Resources;

use MessageBird\Common;
use MessageBird\Objects;

/**
 * Class PhoneNumbers
 *
 * @package MessageBird\Resources
 */
class PhoneNumbers extends Base
{

    /**
     * @var \MessageBird\Common\HttpClient
     */
    protected $httpClient;

    /**
     * @param Common\HttpClient $httpClient
     */
    public function __construct(Common\HttpClient $httpClient)
    {
        $this->httpClient = $httpClient;
        $this->setObject(new Objects\Number());
        $this->setResourceName('phone-numbers');
    }

    /**
     * @param mixed $object
     * @param mixed $id
     *
     * @return Objects\Number
     *
     * @internal param array $parameters
     */
    public function update($object, $id): Objects\Number
    {
        $objVars = get_object_vars($object);
        $body = [];
        foreach ($objVars as $key => $value) {
            if ($value !== null) {
                $body[$key] = $value;
            }
        }

        $resourceName = $this->resourceName . ($id ? '/' . $id : null);
        $body = json_encode($body);

        // This override is only needed to use the PATCH http method
        list(, , $body) = $this->httpClient->performHttpRequest(Common\HttpClient::REQUEST_PATCH, $resourceName, false, $body);
        return $this->processRequest($body);
    }
}
?>
