<?php

namespace bird\traits;

trait bird_endpoint_builder_t
{
    protected function birdEncodePathSegment(string $segment): string
    {
        return rawurlencode($segment);
    }

    protected function birdVoiceCallsBasePath(string $workspaceId, string $channelId): string
    {
        return '/workspaces/'
            . $this->birdEncodePathSegment($workspaceId)
            . '/channels/'
            . $this->birdEncodePathSegment($channelId)
            . '/calls';
    }

    protected function birdVoiceCallPath(string $workspaceId, string $channelId, string $callId): string
    {
        return $this->birdVoiceCallsBasePath($workspaceId, $channelId)
            . '/'
            . $this->birdEncodePathSegment($callId);
    }

    protected function birdVoiceCallCommandPath(string $workspaceId, string $channelId, string $callId, string $command): string
    {
        return $this->birdVoiceCallPath($workspaceId, $channelId, $callId)
            . '/'
            . trim($command, '/');
    }

    protected function birdVoiceCallRecordingsPath(string $workspaceId, string $channelId, string $callId): string
    {
        return $this->birdVoiceCallPath($workspaceId, $channelId, $callId) . '/recordings';
    }

    protected function birdVoiceCallRecordingPath(string $workspaceId, string $channelId, string $callId, string $recordingId): string
    {
        return $this->birdVoiceCallRecordingsPath($workspaceId, $channelId, $callId)
            . '/'
            . $this->birdEncodePathSegment($recordingId);
    }

    protected function birdVoiceCallsLogPath(string $workspaceId): string
    {
        return '/workspaces/' . $this->birdEncodePathSegment($workspaceId) . '/channels/calls';
    }

    protected function birdFlashCallsBasePath(string $workspaceId, string $channelId): string
    {
        return '/workspaces/'
            . $this->birdEncodePathSegment($workspaceId)
            . '/channels/'
            . $this->birdEncodePathSegment($channelId)
            . '/flashcalls';
    }

    protected function birdFlashCallPath(string $workspaceId, string $channelId, string $callId): string
    {
        return $this->birdFlashCallsBasePath($workspaceId, $channelId)
            . '/'
            . $this->birdEncodePathSegment($callId);
    }

    protected function birdFlashCallsHangupPath(string $workspaceId, string $channelId): string
    {
        return $this->birdFlashCallsBasePath($workspaceId, $channelId) . '/hangup';
    }
}

