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

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;

}


#
# list_preferences
#
# List service defaults and exact-type overrides
#
# @param string $organization_id  (required)
{
    my $params = {
    'organization_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'list_preferences' } = {
        summary => 'List service defaults and exact-type overrides',
        params => $params,
        returns => 'ARRAY[ServicePreference]',
        };
}
# @return ARRAY[ServicePreference]
#
sub list_preferences {
    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_preferences");
    }

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

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

#
# remove_type_preference
#
# Remove an exact-type override so it inherits the service default
#
# @param string $service_id  (required)
# @param string $type  (required)
{
    my $params = {
    'service_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'type' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'remove_type_preference' } = {
        summary => 'Remove an exact-type override so it inherits the service default',
        params => $params,
        returns => 'InheritedResponse',
        };
}
# @return InheritedResponse
#
sub remove_type_preference {
    my ($self, %args) = @_;

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

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

    # parse inputs
    my $_resource_path = '/services/{serviceId}/types/{type}/preference';

    my $_method = 'DELETE';
    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{'service_id'}) {
        my $_base_variable = "{" . "serviceId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'service_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    # path params
    if ( exists $args{'type'}) {
        my $_base_variable = "{" . "type" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'type'});
        $_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('InheritedResponse', $response);
    return $_response_object;
}

#
# set_service_preference
#
# Enable or disable pushes for a service by default
#
# @param string $service_id  (required)
# @param SetEnabledInput $set_enabled_input  (required)
{
    my $params = {
    'service_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'set_enabled_input' => {
        data_type => 'SetEnabledInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'set_service_preference' } = {
        summary => 'Enable or disable pushes for a service by default',
        params => $params,
        returns => 'PreferenceRecord',
        };
}
# @return PreferenceRecord
#
sub set_service_preference {
    my ($self, %args) = @_;

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

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

    # parse inputs
    my $_resource_path = '/services/{serviceId}/preference';

    my $_method = 'PUT';
    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{'service_id'}) {
        my $_base_variable = "{" . "serviceId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'service_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    my $_body_data;
    # body params
    if ( exists $args{'set_enabled_input'}) {
        $_body_data = $args{'set_enabled_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('PreferenceRecord', $response);
    return $_response_object;
}

#
# set_type_preference
#
# Override push delivery for one exact notification type
#
# @param string $service_id  (required)
# @param string $type  (required)
# @param SetEnabledInput $set_enabled_input  (required)
{
    my $params = {
    'service_id' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'type' => {
        data_type => 'string',
        description => '',
        required => '1',
    },
    'set_enabled_input' => {
        data_type => 'SetEnabledInput',
        description => '',
        required => '1',
    },
    };
    __PACKAGE__->method_documentation->{ 'set_type_preference' } = {
        summary => 'Override push delivery for one exact notification type',
        params => $params,
        returns => 'PreferenceRecord',
        };
}
# @return PreferenceRecord
#
sub set_type_preference {
    my ($self, %args) = @_;

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

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

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

    # parse inputs
    my $_resource_path = '/services/{serviceId}/types/{type}/preference';

    my $_method = 'PUT';
    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{'service_id'}) {
        my $_base_variable = "{" . "serviceId" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'service_id'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

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

    my $_body_data;
    # body params
    if ( exists $args{'set_enabled_input'}) {
        $_body_data = $args{'set_enabled_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('PreferenceRecord', $response);
    return $_response_object;
}

1;
