=begin comment

Agent Push Kit API

The complete Agent Push Kit REST API. Application event ingestion uses an organization key beginning with `apk_`. Authenticated user operations accept either an Agent Push Kit login JWT or an agent access token beginning with `apt_`.

The version of the OpenAPI document: 0.1.0

Generated by: https://openapi-generator.tech

=end comment

=cut

#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# Do not edit the class manually.
# Ref: https://openapi-generator.tech
#
package AgentPushKit::Client::EventsApi;

require 5.6.0;
use strict;
use warnings;
use utf8;
use Exporter;
use Carp qw( croak );
use Log::Any qw($log);

use AgentPushKit::Client::ApiClient;

use base "Class::Data::Inheritable";

__PACKAGE__->mk_classdata('method_documentation' => {});

sub new {
    my $class = shift;
    my $api_client;

    if ($_[0] && ref $_[0] && ref $_[0] eq 'AgentPushKit::Client::ApiClient' ) {
        $api_client = $_[0];
    } else {
        $api_client = AgentPushKit::Client::ApiClient->new(@_);
    }

    bless { api_client => $api_client }, $class;

}


#
# get_event
#
# Get one event including metadata
#
# @param string $organization_id  (required)
# @param string $event_id  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'event_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'get_event' } = {
        summary => 'Get one event including metadata',
        params => $params,
        returns => 'EventDetail',
        };
}
# @return EventDetail
#
sub get_event {
    my ($self, %args) = @_;

    # verify the required parameter 'organization_id' is set
    unless (exists $args{'organization_id'}) {
      croak("Missing the required parameter 'organization_id' when calling get_event");
    }

    # verify the required parameter 'event_id' is set
    unless (exists $args{'event_id'}) {
      croak("Missing the required parameter 'event_id' when calling get_event");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/events/{eventId}';

    my $_method = 'GET';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type();

    # path params
    if ( exists $args{'organization_id'}) {
        my $_base_variable = "{" . "organizationId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'organization_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    # path params
    if ( exists $args{'event_id'}) {
        my $_base_variable = "{" . "eventId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'event_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # authentication setting, if any
    my $auth_settings = [qw(UserOrAgent )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('EventDetail', $response);
    return $_response_object;
}

#
# list_events
#
# List a paginated inbox
#
# @param string $organization_id  (required)
# @param string $service  (optional)
# @param string $type  (optional)
# @param string $search  (optional)
# @param string $cursor  (optional)
# @param int $limit  (optional, default to 50)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'service' => {
        data_type => 'string',
        description => '',
        required => '0',
    },
    'type' => {
        data_type => 'string',
        description => '',
        required => '0',
    },
    'search' => {
        data_type => 'string',
        description => '',
        required => '0',
    },
    'cursor' => {
        data_type => 'string',
        description => '',
        required => '0',
    },
    'limit' => {
        data_type => 'int',
        description => '',
        required => '0',
    },
    };
    __PACKAGE__->method_documentation->{ 'list_events' } = {
        summary => 'List a paginated inbox',
        params => $params,
        returns => 'EventPage',
        };
}
# @return EventPage
#
sub list_events {
    my ($self, %args) = @_;

    # verify the required parameter 'organization_id' is set
    unless (exists $args{'organization_id'}) {
      croak("Missing the required parameter 'organization_id' when calling list_events");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/events';

    my $_method = 'GET';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type();

    # query params
    if ( exists $args{'service'}) {
        $query_params->{'service'} = $self->{api_client}->to_query_value($args{'service'});
    }

    # query params
    if ( exists $args{'type'}) {
        $query_params->{'type'} = $self->{api_client}->to_query_value($args{'type'});
    }

    # query params
    if ( exists $args{'search'}) {
        $query_params->{'search'} = $self->{api_client}->to_query_value($args{'search'});
    }

    # query params
    if ( exists $args{'cursor'}) {
        $query_params->{'cursor'} = $self->{api_client}->to_query_value($args{'cursor'});
    }

    # query params
    if ( exists $args{'limit'}) {
        $query_params->{'limit'} = $self->{api_client}->to_query_value($args{'limit'});
    }

    # path params
    if ( exists $args{'organization_id'}) {
        my $_base_variable = "{" . "organizationId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'organization_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # authentication setting, if any
    my $auth_settings = [qw(UserOrAgent )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('EventPage', $response);
    return $_response_object;
}

#
# list_notification_types
#
# List distinct notification types
#
# @param string $organization_id  (required)
# @param string $service_id Optionally restrict types to one service ID. (optional)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'service_id' => {
        data_type => 'string',
        description => 'Optionally restrict types to one service ID.',
        required => '0',
    },
    };
    __PACKAGE__->method_documentation->{ 'list_notification_types' } = {
        summary => 'List distinct notification types',
        params => $params,
        returns => 'ARRAY[string]',
        };
}
# @return ARRAY[string]
#
sub list_notification_types {
    my ($self, %args) = @_;

    # verify the required parameter 'organization_id' is set
    unless (exists $args{'organization_id'}) {
      croak("Missing the required parameter 'organization_id' when calling list_notification_types");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/types';

    my $_method = 'GET';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type();

    # query params
    if ( exists $args{'service_id'}) {
        $query_params->{'serviceId'} = $self->{api_client}->to_query_value($args{'service_id'});
    }

    # path params
    if ( exists $args{'organization_id'}) {
        my $_base_variable = "{" . "organizationId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'organization_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # authentication setting, if any
    my $auth_settings = [qw(UserOrAgent )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('ARRAY[string]', $response);
    return $_response_object;
}

#
# list_services
#
# List services discovered from ingested events
#
# @param string $organization_id  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'list_services' } = {
        summary => 'List services discovered from ingested events',
        params => $params,
        returns => 'ARRAY[Service]',
        };
}
# @return ARRAY[Service]
#
sub list_services {
    my ($self, %args) = @_;

    # verify the required parameter 'organization_id' is set
    unless (exists $args{'organization_id'}) {
      croak("Missing the required parameter 'organization_id' when calling list_services");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/services';

    my $_method = 'GET';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type();

    # path params
    if ( exists $args{'organization_id'}) {
        my $_base_variable = "{" . "organizationId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'organization_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # authentication setting, if any
    my $auth_settings = [qw(UserOrAgent )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('ARRAY[Service]', $response);
    return $_response_object;
}

#
# search_events
#
# Search events with a validated Boolean filter tree
#
# @param string $organization_id  (required)
# @param SearchEventsInput $search_events_input  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'search_events_input' => {
        data_type => 'SearchEventsInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'search_events' } = {
        summary => 'Search events with a validated Boolean filter tree',
        params => $params,
        returns => 'EventPage',
        };
}
# @return EventPage
#
sub search_events {
    my ($self, %args) = @_;

    # verify the required parameter 'organization_id' is set
    unless (exists $args{'organization_id'}) {
      croak("Missing the required parameter 'organization_id' when calling search_events");
    }

    # verify the required parameter 'search_events_input' is set
    unless (exists $args{'search_events_input'}) {
      croak("Missing the required parameter 'search_events_input' when calling search_events");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/events/search';

    my $_method = 'POST';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json');

    # path params
    if ( exists $args{'organization_id'}) {
        my $_base_variable = "{" . "organizationId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'organization_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # body params
    if ( exists $args{'search_events_input'}) {
        $_body_data = $args{'search_events_input'};
    }

    # authentication setting, if any
    my $auth_settings = [qw(UserOrAgent )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('EventPage', $response);
    return $_response_object;
}

#
# send_event
#
# Send an event using an application ingestion key
#
# @param SendEventInput $send_event_input  (required)
{
    my $params = {
    'send_event_input' => {
        data_type => 'SendEventInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'send_event' } = {
        summary => 'Send an event using an application ingestion key',
        params => $params,
        returns => 'IngestionResult',
        };
}
# @return IngestionResult
#
sub send_event {
    my ($self, %args) = @_;

    # verify the required parameter 'send_event_input' is set
    unless (exists $args{'send_event_input'}) {
      croak("Missing the required parameter 'send_event_input' when calling send_event");
    }

    # parse inputs
    my $_resource_path = '/events';

    my $_method = 'POST';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json');

    my $_body_data;
    # body params
    if ( exists $args{'send_event_input'}) {
        $_body_data = $args{'send_event_input'};
    }

    # authentication setting, if any
    my $auth_settings = [qw(OrganizationApiKey )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('IngestionResult', $response);
    return $_response_object;
}

#
# send_event_as_user
#
# Send an event as an authenticated user or agent
#
# @param string $organization_id  (required)
# @param SendEventInput $send_event_input  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'send_event_input' => {
        data_type => 'SendEventInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'send_event_as_user' } = {
        summary => 'Send an event as an authenticated user or agent',
        params => $params,
        returns => 'IngestionResult',
        };
}
# @return IngestionResult
#
sub send_event_as_user {
    my ($self, %args) = @_;

    # verify the required parameter 'organization_id' is set
    unless (exists $args{'organization_id'}) {
      croak("Missing the required parameter 'organization_id' when calling send_event_as_user");
    }

    # verify the required parameter 'send_event_input' is set
    unless (exists $args{'send_event_input'}) {
      croak("Missing the required parameter 'send_event_input' when calling send_event_as_user");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/events';

    my $_method = 'POST';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept('application/json');
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type('application/json');

    # path params
    if ( exists $args{'organization_id'}) {
        my $_base_variable = "{" . "organizationId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'organization_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # body params
    if ( exists $args{'send_event_input'}) {
        $_body_data = $args{'send_event_input'};
    }

    # authentication setting, if any
    my $auth_settings = [qw(UserOrAgent )];

    # make the API Call
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('IngestionResult', $response);
    return $_response_object;
}

1;
