<?php

/**
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Sample/reference Twilio API.
 * This is the reference API for the rest-proxy server.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Twilio\Rest\Insights\V2;

use Twilio\Exceptions\TwilioException;
use Twilio\Values;
use Twilio\Version;
use Twilio\InstanceContext;
use Twilio\Http\Response;
use Twilio\Metadata\ResourceMetadata;


class ReportContext extends InstanceContext
    {
    /**
     * Initialize the ReportContext
     *
     * @param Version $version Version that contains the resource
     * @param string $reportId A unique request id.
     */
    public function __construct(
        Version $version,
        $reportId
    ) {
        parent::__construct($version);

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

        $this->uri = '/Voice/Reports';
    }

    /**
     * Helper function for Create
     *
     * @param ?InsightsV2CreateAccountReportRequest $insightsV2CreateAccountReportRequest
     * @return Response Created Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _create(?InsightsV2CreateAccountReportRequest $insightsV2CreateAccountReportRequest = null): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/json', 'Accept' => 'application/json' ]);
        $data = $insightsV2CreateAccountReportRequest ? $insightsV2CreateAccountReportRequest->toArray() : [];
        return $this->version->handleRequest('POST', $this->uri, [], $data, $headers, "create");
    }

    /**
     * Create the ReportInstance
     *
     * @param ?InsightsV2CreateAccountReportRequest $insightsV2CreateAccountReportRequest
     * @return ReportInstance Created ReportInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function create(?InsightsV2CreateAccountReportRequest $insightsV2CreateAccountReportRequest = null): ReportInstance
    {
        $response = $this->_create($insightsV2CreateAccountReportRequest);
        return new ReportInstance(
            $this->version,
            $response->getContent()
        );
        
    }

    /**
     * Create the ReportInstance with Metadata
     *
     * @param ?InsightsV2CreateAccountReportRequest $insightsV2CreateAccountReportRequest
     * @return ResourceMetadata The Created Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function createWithMetadata(?InsightsV2CreateAccountReportRequest $insightsV2CreateAccountReportRequest = null): ResourceMetadata
    {
        $response = $this->_create($insightsV2CreateAccountReportRequest);
        $resource = new ReportInstance(
                        $this->version,
                        $response->getContent()
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Helper function for Fetch
     *
     
     * @return Response Fetched Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _fetch(): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]);
        return $this->version->handleRequest('GET', $this->uri, [], [], $headers, "fetch");
    }

    /**
     * Fetch the ReportInstance
     *
     
     * @return ReportInstance Fetched ReportInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): ReportInstance
    {
        $response = $this->_fetch();
        return new ReportInstance(
            $this->version,
            $response->getContent(),
            $this->solution['reportId']
        );
        
    }

    /**
     * Fetch the ReportInstance with Metadata
     *
     
     * @return ResourceMetadata The Fetched Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetchWithMetadata(): ResourceMetadata
    {
        $response = $this->_fetch();
        $resource = new ReportInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['reportId']
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * 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.Insights.V2.ReportContext ' . \implode(' ', $context) . ']';
    }
}
