<?php

namespace Tops\AmazonSellingPartnerAPI\Api;

class Sts extends BaseApi
{
    public function getSessionToken(string $roleArn)
    {
        $resource_path = '/';
        $http_body = '';
        $query_params = [];
        $method = 'GET';

        $query_params['Version'] = "2011-06-15";
        $query_params['Action'] = "AssumeRole";
        $query_params['RoleSessionName'] = "spapi-assumerole-".time();
        $query_params['RoleArn'] = $roleArn;
        $query_params['DurationSeconds'] = 3600;

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method, "sts");
        $url = $this->config->getHost() . $resource_path;

        $response = $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);

        return $response['AssumeRoleResponse']['AssumeRoleResult']['Credentials'] ?? null;
    }
}
