<?php

/**
 * This code was generated by
 * \ / _    _  _|   _  _
 * | (_)\/(_)(_|\/| |(/_  v1.0.0
 * /       /
 */

namespace Twilio\Rest\Fax\V1\Fax;

use Twilio\Exceptions\TwilioException;
use Twilio\InstanceContext;
use Twilio\Values;
use Twilio\Version;

/**
 * PLEASE NOTE that this class contains beta products that are subject to change. Use them with caution.
 */
class FaxMediaContext extends InstanceContext {
    /**
     * Initialize the FaxMediaContext
     *
     * @param Version $version Version that contains the resource
     * @param string $faxSid The SID of the fax with the FaxMedia resource to fetch
     * @param string $sid The unique string that identifies the resource to fetch
     */
    public function __construct(Version $version, $faxSid, $sid) {
        parent::__construct($version);

        // Path Solution
        $this->solution = ['faxSid' => $faxSid, 'sid' => $sid, ];

        $this->uri = '/Faxes/' . \rawurlencode($faxSid) . '/Media/' . \rawurlencode($sid) . '';
    }

    /**
     * Fetch the FaxMediaInstance
     *
     * @return FaxMediaInstance Fetched FaxMediaInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): FaxMediaInstance {
        $payload = $this->version->fetch('GET', $this->uri);

        return new FaxMediaInstance(
            $this->version,
            $payload,
            $this->solution['faxSid'],
            $this->solution['sid']
        );
    }

    /**
     * Delete the FaxMediaInstance
     *
     * @return bool True if delete succeeds, false otherwise
     * @throws TwilioException When an HTTP error occurs.
     */
    public function delete(): bool {
        return $this->version->delete('DELETE', $this->uri);
    }

    /**
     * Provide a friendly representation
     *
     * @return string Machine friendly representation
     */
    public function __toString(): string {
        $context = [];
        foreach ($this->solution as $key => $value) {
            $context[] = "$key=$value";
        }
        return '[Twilio.Fax.V1.FaxMediaContext ' . \implode(' ', $context) . ']';
    }
}