<?php

namespace Tops\AmazonSellingPartnerAPI\Api;

class FinancesApi extends BaseApi
{
    /**
    * Operation List Financial Event Groups
    *
    * @param array $params
    * @param integer $params['MaxResultsPerPage'] The maximum number of results to return per page. <Minimum : 1, Maximum : 100>
    * @param string (date-time) $params['FinancialEventGroupStartedBefore'] A date used for selecting financial event groups that opened before (but not at) a specified date and time, in ISO 8601 format. The date-time must be later than FinancialEventGroupStartedAfter and no later than two minutes before the request was submitted. If FinancialEventGroupStartedAfter and FinancialEventGroupStartedBefore are more than 180 days apart, no financial event groups are returned.
    * @param string (date-time) $params['FinancialEventGroupStartedAfter'] A date used for selecting financial event groups that opened after (or at) a specified date and time, in ISO 8601 format. The date-time must be no later than two minutes before the request was submitted.
    * @param string $params['NextToken'] A string token returned in the response of your previous request.
    *
    * @return json\
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * about more Ref: https://github.com/amzn/selling-partner-api-docs/blob/main/references/finances-api/financesV0.md#listfinancialeventgroups
    */
    public function listFinancialEventGroups($params)
    {
        $resource_path = '/finances/v0/financialEventGroups';
        $url = $this->config->getHost() . $resource_path;
        $http_body = '';
        $query_params = [];
        $method = 'GET';

        if (array_key_exists('MaxResultsPerPage', $params) && $params['MaxResultsPerPage'] !== null) {
            $query_params['MaxResultsPerPage'] = $params['MaxResultsPerPage'];
        }

        if (array_key_exists('FinancialEventGroupStartedBefore', $params) && $params['FinancialEventGroupStartedBefore'] !== null) {
            $query_params['FinancialEventGroupStartedBefore'] = $params['FinancialEventGroupStartedBefore'];
        }

        if (array_key_exists('FinancialEventGroupStartedAfter', $params) && $params['FinancialEventGroupStartedAfter'] !== null) {
            $query_params['FinancialEventGroupStartedAfter'] = $params['FinancialEventGroupStartedAfter'];
        }

        if (array_key_exists('NextToken', $params) && $params['NextToken'] !== null) {
            $query_params['NextToken'] = $params['NextToken'];
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
    /**
    * Operation List Financial Events By GroupId
    *
    * @param integer $params['MaxResultsPerPage']   The maximum number of results to return per page. <Minimum : 1 & Maximum : 100>
    * @param string $params['NextToken'] A string token returned in the response of your previous request.
    * @param string $event_group_id The identifier of the financial event group to which the events belong. (required)
    *
    * @return json\
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    *  about more Ref: https://github.com/amzn/selling-partner-api-docs/blob/main/references/finances-api/financesV0.md#listfinancialeventsbygroupid
    */
    public function listFinancialEventsByGroupId($params, $event_group_id)
    {
        $resource_path = '/finances/v0/financialEventGroups/{eventGroupId}/financialEvents';
        $url = $this->config->getHost() . $resource_path;
        $http_body = '';
        $query_params = [];
        $method = 'GET';

        // query Param
        if (array_key_exists('MaxResultsPerPage', $params) && $params['MaxResultsPerPage'] !== null) {
            $query_params['MaxResultsPerPage'] = $params['MaxResultsPerPage'];
        }

        if (array_key_exists('NextToken', $params) && $params['NextToken'] !== null) {
            $query_params['NextToken'] =  $params['NextToken'];
        }

        // path params
        if (null !== $event_group_id) {
            $resource_path = str_replace(
                '{' . 'eventGroupId' . '}',
                $event_group_id,
                $resource_path
            );
        }
        

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation List Financial Events By OrderId
    *
    * @param integer $params['MaxResultsPerPage']   The maximum number of results to return per page. <Minimum : 1 & Maximum : 100>
    * @param string $params['NextToken'] A string token returned in the response of your previous request.
    * @param string $event_group_id
    *
    * @return json\
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * about more ref: https://github.com/amzn/selling-partner-api-docs/blob/main/references/finances-api/financesV0.md#listfinancialeventsbyorderid
    */
    public function listFinancialEventsByOrderId($params, $order_id)
    {
        $resource_path = '/finances/v0/orders/{orderId}/financialEvents';
        $url = $this->config->getHost() . $resource_path;
        $http_body = '';
        $query_params = [];
        $method = 'GET';
        
        // path params
        if (null !== $order_id) {
            $resource_path = str_replace(
                '{' . 'orderId' . '}',
                $order_id,
                $resource_path
            );
        }
      

        // query param
        if (array_key_exists('MaxResultsPerPage', $params) && $params['MaxResultsPerPage'] !== null) {
            $query_params['MaxResultsPerPage'] = $params['MaxResultsPerPage'];
        }
        if (array_key_exists('NextToken', $params) && $params['NextToken'] !== null) {
            $query_params['NextToken'] = $params['NextToken'];
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
    * Operation List Financial Events
    *
    * @param integer $params['MaxResultsPerPage']   The maximum number of results to return per page. <Minimum : 1 & Maximum : 100>
    * @param string (date-time) $params['PostedAfter']  A date used for selecting financial events posted after (or at) a specified time. The date-time must be no later than two minutes before the request was submitted, in ISO 8601 date time format.
    * @param string (date-time) $params['PostedBefore'] A date used for selecting financial events posted before (but not at) a specified time. The date-time must be later than PostedAfter and no later than two minutes before the request was submitted, in ISO 8601 date time format.
    * @param string $params['NextToken'] A string token returned in the response of your previous request.
    *
    * @return json\
    *
    * @author Chetan Meena <chetan@topsinfosolutions.com>
    *
    * About more Ref: https://github.com/amzn/selling-partner-api-docs/blob/main/references/finances-api/financesV0.md#listfinancialevents
    */
    public function listFinancialEvents($params)
    {
        $resource_path = '/finances/v0/financialEvents';
        $url = $this->config->getHost() . $resource_path;
        $http_body = '';
        $query_params = [];
        $method = 'GET';

        // query param
        if (array_key_exists('MaxResultsPerPage', $params) && $params['MaxResultsPerPage'] !== null) {
            $query_params['MaxResultsPerPage'] = $params['MaxResultsPerPage'];
        }
        if (array_key_exists('PostedAfter', $params) && $params['PostedAfter'] !== null) {
            $query_params['PostedAfter'] = $params['PostedAfter'];
        }
        if (array_key_exists('PostedBefore ', $params) && $params['PostedBefore '] !== null) {
            $query_params['PostedBefore '] = $params['PostedBefore '];
        }
        if (array_key_exists('NextToken', $params) && $params['NextToken'] !== null) {
            $query_params['NextToken'] = $params['NextToken'];
        }

        $curl_headers = $this->generateRequest($resource_path, $query_params, $http_body, $this->config, $method);

        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
}
