<?php

namespace Fifa\ConnectId\Sdk\Authentication;

use Fifa\ConnectServiceBus\Sdk\Authentication\AuthenticationResourceBuilderInterface;
use UnexpectedValueException;

/**
 * Class ConnectIdAuthenticationResourceBuilder
 * @package Fifa\ConnectId\Sdk\Authentication
 */
class ConnectIdAuthenticationResourceBuilder implements AuthenticationResourceBuilderInterface
{
    private $mapping = array(
        'https://fci-apim-int.azure-api.net/hashing'       => 'fci-hashing-int',
        'https://fci-apim-int.azure-api.net/iddirectory'   => 'fci-iddirectory-int',
        'https://fci-apim-hfix.azure-api.net/hashing'      => 'fci-hashing-hfix',
        'https://fci-apim-hfix.azure-api.net/iddirectory'  => 'fci-iddirectory-hfix',
        'https://fci-apim-beta.azure-api.net/hashing'      => 'fci-hashing-beta',
        'https://fci-apim-beta.azure-api.net/iddirectory'  => 'fci-iddirectory-beta',
        'https://fci-apim-prep.azure-api.net/hashing'      => 'fci-hashing-prep',
        'https://fci-apim-prep.azure-api.net/iddirectory'  => 'fci-iddirectory-prep',
        'https://fci-apim-prod.azure-api.net/hashing'      => 'fci-hashing-prod',
        'https://fci-apim-prod.azure-api.net/iddirectory'  => 'fci-iddirectory-prod'
    );

    /**
     * Returns resource Uri string
     *
     * @param string $serviceUri
     * @param string $tenant
     * @return string
     * @throws UnexpectedValueException
     */
    public function buildResourceUri(string $serviceUri, string $tenant): string
    {
        if (!isset($this->mapping[$serviceUri])) {
            throw new UnexpectedValueException('Provided mapping array doesn\'t contain key: ' . $serviceUri);
        }

        return 'https://' . $tenant . '/' . $this->mapping[$serviceUri];
    }
}