<?php

namespace Tops\AmazonSellingPartnerAPI\Api;

class ServiceApi extends BaseApi
{
    /**
     * Operation Get Service Job By Service Job Id
     *
     * @param string $service_job_id A service job identifier. (required)
     *
     * @return json
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/services-api/services.md#getservicejobbyservicejobid
     */
    public function getServiceJobByServiceJobId($service_job_id)
    {
        if (null === $service_job_id) {
            throw new \InvalidArgumentException('Missing the required parameter $service_job_id when calling getReport');
        }

        $resource_path = '/service/v1/serviceJobs/{serviceJobId}';
        $query_params = [];
        $http_body = '';
        $method = 'GET';

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

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

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation Cancel Service Job By Service Job Id
     *
     * @param string $service_job_id A service job identifier. < minLength : 1 and maxLength : 100> (required)
     * @param string $cancellation_reason_code A cancel reason code that specifies the reason for cancelling a service job. < minLength : 1 and maxLength : 100> (required)
     *
     * @return json
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/services-api/services.md#cancelservicejobbyservicejobid
     */
    public function cancelServiceJobByServiceJobId($service_job_id, $cancellation_reason_code)
    {
        if (null === $service_job_id) {
            throw new \InvalidArgumentException('Missing the required parameter $service_job_id when calling cancelServiceJobByServiceJobId');
        }
        if (null === $cancellation_reason_code) {
            throw new \InvalidArgumentException('Missing the required parameter $cancellation_reason_code when calling cancelServiceJobByServiceJobId');
        }
        $resource_path = '/service/v1/serviceJobs/{serviceJobId}/cancellations';
        $query_params = [];
        $http_body = '';
        $method = 'PUT';

        // get Query params
        if ($cancellation_reason_code !== null) {
            $query_params['cancellationReasonCode'] = $cancellation_reason_code;
        }

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

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

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation complete Service Job By ServiceJobId
     *
     * @param string $service_job_id A service job identifier. < minLength : 1 and maxLength : 100>
     *
     * @return json
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref:- https://github.com/amzn/selling-partner-api-docs/blob/main/references/services-api/services.md#completeservicejobbyservicejobid
     */
    public function completeServiceJobByServiceJobId($service_job_id)
    {
        if (null === $service_job_id) {
            throw new \InvalidArgumentException('Missing the required parameter $service_job_id when calling completeServiceJobByServiceJobId');
        }

        $resource_path = '/service/v1/serviceJobs/{serviceJobId}/completions';
        $query_params = [];
        $http_body = '';
        $method = 'GET';

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

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

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
    /**
     * Operation Get Service Jobs
     *
     * @param string|array $params['serviceOrderIds'] List of service order ids for the query you want to perform.Max values supported 20
     * @param string|array $params['serviceJobStatus'] A list of one or more job status by which to filter the list of jobs.
     * @param array $params['pageToken'] String returned in the response of your previous request.
     * @param integer $params['pageSize'] A non-negative integer that indicates the maximum number of jobs to return in the list, Value must be 1 - 20. Default 20.
     * @param enum $params['sortField'] Sort fields on which you want to sort the output.
     * @param enum $params['sortOrder'] Sort order for the query you want to perform.
     * @param string $params['createdAfter'] A date used for selecting jobs created after (or at) a specified time must be in ISO 8601 format. Required if LastUpdatedAfter is not specified.Specifying both CreatedAfter and LastUpdatedAfter returns an error.
     * @param string $params['createdBefore'] A date used for selecting jobs created before (or at) a specified time must be in ISO 8601 format.
     * @param string $params['lastUpdatedAfter'] A date used for selecting jobs updated after (or at) a specified time must be in ISO 8601 format. Required if createdAfter is not specified.Specifying both CreatedAfter and LastUpdatedAfter returns an error.
     * @param string $params['lastUpdatedBefore'] A date used for selecting jobs updated before (or at) a specified time must be in ISO 8601 format.
     * @param string $params['scheduleStartDate'] A date used for filtering jobs schedule after (or at) a specified time must be in ISO 8601 format. schedule end date should not be earlier than schedule start date.
     * @param string $params['scheduleEndDate'] A date used for filtering jobs schedule before (or at) a specified time must be in ISO 8601 format. schedule end date should not be earlier than schedule start date.
     * @param string|array $params['marketplaceIds'] Used to select jobs that were placed in the specified marketplaces.
     *
     *
     * @return json Returns a list of marketplaces that the seller submitting the request can sell in and information about the seller's participation in those marketplaces.
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref :- https://github.com/amzn/selling-partner-api-docs/blob/main/references/services-api/services.md#getservicejobs
     */
    public function getServiceJobs($params)
    {
        if (!array_key_exists('marketplaceIds', $params) ||  null === $params['marketplaceIds']) {
            throw new \InvalidArgumentException('Missing the required parameter $marketplaceIds when calling getServiceJobs');
        }
        $resource_path = '/service/v1/serviceJobs';
        $query_params = [];
        $http_body = '';
        $method = 'GET';

        // get Query params
        if (array_key_exists('serviceOrderIds', $params) && $params['serviceOrderIds'] !== null) {
            $query_params['serviceOrderIds'] = $params['serviceOrderIds'];
        }
        if (array_key_exists('serviceJobStatus', $params) && $params['serviceJobStatus'] !== null) {
            $query_params['serviceJobStatus'] = $params['serviceJobStatus'];
        }
        if (array_key_exists('pageToken', $params) && $params['pageToken'] !== null) {
            $query_params['pageToken'] = $params['pageToken'];
        }
        if (array_key_exists('pageSize', $params) && $params['pageSize'] !== null) {
            $query_params['pageSize'] = $params['pageSize'];
        }
        if (array_key_exists('sortField', $params) && $params['sortField'] !== null) {
            $query_params['sortField'] = $params['sortField'];
        }
        if (array_key_exists('sortOrder', $params) && $params['sortOrder'] !== null) {
            $query_params['sortOrder'] = $params['sortOrder'];
        }
        if (array_key_exists('createdAfter', $params) && $params['createdAfter'] !== null) {
            $query_params['createdAfter'] = $params['createdAfter'];
        }
        if (array_key_exists('createdBefore', $params) && $params['createdBefore'] !== null) {
            $query_params['createdBefore'] = $params['createdBefore'];
        }
        if (array_key_exists('lastUpdatedAfter', $params) && $params['lastUpdatedAfter'] !== null) {
            $query_params['lastUpdatedAfter'] = $params['lastUpdatedAfter'];
        }
        if (array_key_exists('lastUpdatedBefore', $params) && $params['lastUpdatedBefore'] !== null) {
            $query_params['lastUpdatedBefore'] = $params['lastUpdatedBefore'];
        }
        if (array_key_exists('scheduleStartDate', $params) && $params['scheduleStartDate'] !== null) {
            $query_params['scheduleStartDate'] = $params['scheduleStartDate'];
        }
        if (array_key_exists('scheduleEndDate', $params) && $params['scheduleEndDate'] !== null) {
            $query_params['scheduleEndDate'] = $params['scheduleEndDate'];
        }
        if (array_key_exists('marketplaceIds', $params) && $params['marketplaceIds'] !== null) {
            $query_params['marketplaceIds'] = is_array($params['marketplaceIds']) ? implode(',', $params['marketplaceIds']) : $params['marketplaceIds'];
        }


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

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
    /**
     * Operation Add Appointment For Service Job By ServiceJobId
     *
     * @param $body Add appointment operation input details.     *
     * @param string $service_job_id An Amazon defined service job identifier. < minLength : 1 maxLength : 100>
     *
     * @return json Returns a list of marketplaces that the seller submitting the request can sell in and information about the seller's participation in those marketplaces.
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     *
     * About more Ref:- https://github.com/amzn/selling-partner-api-docs/blob/main/references/services-api/services.md#addappointmentforservicejobbyservicejobid
     */
    public function addAppointmentForServiceJobByServiceJobId($body, $service_job_id)
    {
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling addAppointmentForServiceJobByServiceJobId');
        }
        if (null === $service_job_id) {
            throw new \InvalidArgumentException('Missing the required parameter $service_job_id when calling addAppointmentForServiceJobByServiceJobId');
        }
        $resource_path = '/service/v1/serviceJobs/{serviceJobId}/appointments';
        $query_params = [];
        $http_body = $body;
        $method = 'POST';

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

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

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }

    /**
     * Operation Reschedule Appointment For Service Job By ServiceJobId
     *
     * @param $body Reschedule appointment operation input details.
     *
     * @param string $service_job_id An Amazon defined service job identifier. < minLength : 1 maxLength : 100>
     *
     * @param string $appointment_id An existing appointment identifier for the Service Job. < minLength : 1 maxLength : 100>
     *
     * @return json
     *
     * @author Chetan Meena <chetan@topsinfosolutions.com>
     */
    public function rescheduleAppointmentForServiceJobByServiceJobId($body, $service_job_id, $appointment_id)
    {
        if (null === $body) {
            throw new \InvalidArgumentException('Missing the required parameter $body when calling rescheduleAppointmentForServiceJobByServiceJobId');
        }
        if (null === $service_job_id) {
            throw new \InvalidArgumentException('Missing the required parameter $service_job_id when calling rescheduleAppointmentForServiceJobByServiceJobId');
        }
        if (null === $appointment_id) {
            throw new \InvalidArgumentException('Missing the required parameter $appointment_id when calling rescheduleAppointmentForServiceJobByServiceJobId');
        }
        $resource_path = '/service/v1/serviceJobs/{serviceJobId}/appointments/{appointmentId}';
        $query_params = [];
        $http_body = http_build_query($body);
        $method = 'POST';

        // path params
        if (null !== $service_job_id) {
            $resource_path = str_replace(
                '{' . 'serviceJobId' . '}',
                $service_job_id,
                $resource_path
            );
        }
        if (null !== $appointment_id) {
            $resource_path = str_replace(
                '{' . 'appointmentId' . '}',
                $appointment_id,
                $resource_path
            );
        }

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

        $url = $this->config->getHost() . $resource_path;
        return $this->sendRequest($url, $query_params, $http_body, $curl_headers, $method);
    }
}
