=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::CustomerAccountsApi;

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;

}


#
# add_organization_member
#
# Add an already-registered user to a customer account
#
# @param string $organization_id  (required)
# @param AddMemberInput $add_member_input  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'add_member_input' => {
        data_type => 'AddMemberInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'add_organization_member' } = {
        summary => 'Add an already-registered user to a customer account',
        params => $params,
        returns => 'Membership',
        };
}
# @return Membership
#
sub add_organization_member {
    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 add_organization_member");
    }

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

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

    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{'add_member_input'}) {
        $_body_data = $args{'add_member_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('Membership', $response);
    return $_response_object;
}

#
# create_organization
#
# Create another Agent Push Kit customer account
#
# @param CreateOrganizationInput $create_organization_input  (required)
{
    my $params = {
    'create_organization_input' => {
        data_type => 'CreateOrganizationInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'create_organization' } = {
        summary => 'Create another Agent Push Kit customer account',
        params => $params,
        returns => 'OrganizationCreated',
        };
}
# @return OrganizationCreated
#
sub create_organization {
    my ($self, %args) = @_;

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

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

    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{'create_organization_input'}) {
        $_body_data = $args{'create_organization_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('OrganizationCreated', $response);
    return $_response_object;
}

#
# list_organization_members
#
# List members of a customer account
#
# @param string $organization_id  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'list_organization_members' } = {
        summary => 'List members of a customer account',
        params => $params,
        returns => 'ARRAY[Membership]',
        };
}
# @return ARRAY[Membership]
#
sub list_organization_members {
    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_organization_members");
    }

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

    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[Membership]', $response);
    return $_response_object;
}

#
# list_organizations
#
# List customer accounts available to the current user
#
{
    my $params = {
    };
    __PACKAGE__->method_documentation->{ 'list_organizations' } = {
        summary => 'List customer accounts available to the current user',
        params => $params,
        returns => 'ARRAY[Organization]',
        };
}
# @return ARRAY[Organization]
#
sub list_organizations {
    my ($self, %args) = @_;

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

    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();

    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[Organization]', $response);
    return $_response_object;
}

#
# regenerate_organization_api_key
#
# Rotate the application event-ingestion key
#
# @param string $organization_id  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'regenerate_organization_api_key' } = {
        summary => 'Rotate the application event-ingestion key',
        params => $params,
        returns => 'OrganizationApiKeyCreated',
        };
}
# @return OrganizationApiKeyCreated
#
sub regenerate_organization_api_key {
    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 regenerate_organization_api_key");
    }

    # parse inputs
    my $_resource_path = '/organizations/{organizationId}/api-key/regenerate';

    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();

    # 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('OrganizationApiKeyCreated', $response);
    return $_response_object;
}

1;
