=begin comment

OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.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 WWW::OpenAPIClient::Object::XmlItem;

require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Date::Parse;
use DateTime;


use base ("Class::Accessor", "Class::Data::Inheritable");

#
#
#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually.
# REF: https://openapi-generator.tech
#

=begin comment

OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.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__->mk_classdata('attribute_map' => {});
__PACKAGE__->mk_classdata('openapi_types' => {});
__PACKAGE__->mk_classdata('method_documentation' => {}); 
__PACKAGE__->mk_classdata('class_documentation' => {});

# new plain object
sub new { 
    my ($class, %args) = @_; 

    my $self = bless {}, $class;

    $self->init(%args);
    
    return $self;
}

# initialize the object
sub init
{
    my ($self, %args) = @_;

    foreach my $attribute (keys %{$self->attribute_map}) {
        my $args_key = $self->attribute_map->{$attribute};
        $self->$attribute( $args{ $args_key } );
    }
}

# return perl hash
sub to_hash {
    my $self = shift;
    my $_hash = decode_json(JSON->new->convert_blessed->encode($self));

    return $_hash;
}

# used by JSON for serialization
sub TO_JSON { 
    my $self = shift;
    my $_data = {};
    foreach my $_key (keys %{$self->attribute_map}) {
        if (defined $self->{$_key}) {
            $_data->{$self->attribute_map->{$_key}} = $self->{$_key};
        }
    }

    return $_data;
}

# from Perl hashref
sub from_hash {
    my ($self, $hash) = @_;

    # loop through attributes and use openapi_types to deserialize the data
    while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
        my $_json_attribute = $self->attribute_map->{$_key}; 
        if ($_type =~ /^array\[(.+)\]$/i) { # array
            my $_subclass = $1;
            my @_array = ();
            foreach my $_element (@{$hash->{$_json_attribute}}) {
                push @_array, $self->_deserialize($_subclass, $_element);
            }
            $self->{$_key} = \@_array;
        } elsif ($_type =~ /^hash\[string,(.+)\]$/i) { # hash
            my $_subclass = $1;
            my %_hash = ();
            while (my($_key, $_element) = each %{$hash->{$_json_attribute}}) {
                $_hash{$_key} = $self->_deserialize($_subclass, $_element);
            }
            $self->{$_key} = \%_hash;
        } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime
            $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute});
        } else {
            $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute);
        }
    }
  
    return $self;
}

# deserialize non-array data
sub _deserialize {
    my ($self, $type, $data) = @_;
    $log->debugf("deserializing %s with %s",Dumper($data), $type);

    if ($type eq 'DateTime') {
        return DateTime->from_epoch(epoch => str2time($data));
    } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
        return $data;
    } else { # hash(model)
        my $_instance = eval "WWW::OpenAPIClient::Object::$type->new()";
        return $_instance->from_hash($data);
    }
}



__PACKAGE__->class_documentation({description => '',
                                  class => 'XmlItem',
                                  required => [], # TODO
}                                 );

__PACKAGE__->method_documentation({
    'attribute_string' => {
        datatype => 'string',
        base_name => 'attribute_string',
        description => '',
        format => '',
        read_only => '',
            },
    'attribute_number' => {
        datatype => 'double',
        base_name => 'attribute_number',
        description => '',
        format => '',
        read_only => '',
            },
    'attribute_integer' => {
        datatype => 'int',
        base_name => 'attribute_integer',
        description => '',
        format => '',
        read_only => '',
            },
    'attribute_boolean' => {
        datatype => 'boolean',
        base_name => 'attribute_boolean',
        description => '',
        format => '',
        read_only => '',
            },
    'wrapped_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'wrapped_array',
        description => '',
        format => '',
        read_only => '',
            },
    'name_string' => {
        datatype => 'string',
        base_name => 'name_string',
        description => '',
        format => '',
        read_only => '',
            },
    'name_number' => {
        datatype => 'double',
        base_name => 'name_number',
        description => '',
        format => '',
        read_only => '',
            },
    'name_integer' => {
        datatype => 'int',
        base_name => 'name_integer',
        description => '',
        format => '',
        read_only => '',
            },
    'name_boolean' => {
        datatype => 'boolean',
        base_name => 'name_boolean',
        description => '',
        format => '',
        read_only => '',
            },
    'name_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'name_array',
        description => '',
        format => '',
        read_only => '',
            },
    'name_wrapped_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'name_wrapped_array',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_string' => {
        datatype => 'string',
        base_name => 'prefix_string',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_number' => {
        datatype => 'double',
        base_name => 'prefix_number',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_integer' => {
        datatype => 'int',
        base_name => 'prefix_integer',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_boolean' => {
        datatype => 'boolean',
        base_name => 'prefix_boolean',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'prefix_array',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_wrapped_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'prefix_wrapped_array',
        description => '',
        format => '',
        read_only => '',
            },
    'namespace_string' => {
        datatype => 'string',
        base_name => 'namespace_string',
        description => '',
        format => '',
        read_only => '',
            },
    'namespace_number' => {
        datatype => 'double',
        base_name => 'namespace_number',
        description => '',
        format => '',
        read_only => '',
            },
    'namespace_integer' => {
        datatype => 'int',
        base_name => 'namespace_integer',
        description => '',
        format => '',
        read_only => '',
            },
    'namespace_boolean' => {
        datatype => 'boolean',
        base_name => 'namespace_boolean',
        description => '',
        format => '',
        read_only => '',
            },
    'namespace_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'namespace_array',
        description => '',
        format => '',
        read_only => '',
            },
    'namespace_wrapped_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'namespace_wrapped_array',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_ns_string' => {
        datatype => 'string',
        base_name => 'prefix_ns_string',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_ns_number' => {
        datatype => 'double',
        base_name => 'prefix_ns_number',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_ns_integer' => {
        datatype => 'int',
        base_name => 'prefix_ns_integer',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_ns_boolean' => {
        datatype => 'boolean',
        base_name => 'prefix_ns_boolean',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_ns_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'prefix_ns_array',
        description => '',
        format => '',
        read_only => '',
            },
    'prefix_ns_wrapped_array' => {
        datatype => 'ARRAY[int]',
        base_name => 'prefix_ns_wrapped_array',
        description => '',
        format => '',
        read_only => '',
            },
});

__PACKAGE__->openapi_types( {
    'attribute_string' => 'string',
    'attribute_number' => 'double',
    'attribute_integer' => 'int',
    'attribute_boolean' => 'boolean',
    'wrapped_array' => 'ARRAY[int]',
    'name_string' => 'string',
    'name_number' => 'double',
    'name_integer' => 'int',
    'name_boolean' => 'boolean',
    'name_array' => 'ARRAY[int]',
    'name_wrapped_array' => 'ARRAY[int]',
    'prefix_string' => 'string',
    'prefix_number' => 'double',
    'prefix_integer' => 'int',
    'prefix_boolean' => 'boolean',
    'prefix_array' => 'ARRAY[int]',
    'prefix_wrapped_array' => 'ARRAY[int]',
    'namespace_string' => 'string',
    'namespace_number' => 'double',
    'namespace_integer' => 'int',
    'namespace_boolean' => 'boolean',
    'namespace_array' => 'ARRAY[int]',
    'namespace_wrapped_array' => 'ARRAY[int]',
    'prefix_ns_string' => 'string',
    'prefix_ns_number' => 'double',
    'prefix_ns_integer' => 'int',
    'prefix_ns_boolean' => 'boolean',
    'prefix_ns_array' => 'ARRAY[int]',
    'prefix_ns_wrapped_array' => 'ARRAY[int]'
} );

__PACKAGE__->attribute_map( {
    'attribute_string' => 'attribute_string',
    'attribute_number' => 'attribute_number',
    'attribute_integer' => 'attribute_integer',
    'attribute_boolean' => 'attribute_boolean',
    'wrapped_array' => 'wrapped_array',
    'name_string' => 'name_string',
    'name_number' => 'name_number',
    'name_integer' => 'name_integer',
    'name_boolean' => 'name_boolean',
    'name_array' => 'name_array',
    'name_wrapped_array' => 'name_wrapped_array',
    'prefix_string' => 'prefix_string',
    'prefix_number' => 'prefix_number',
    'prefix_integer' => 'prefix_integer',
    'prefix_boolean' => 'prefix_boolean',
    'prefix_array' => 'prefix_array',
    'prefix_wrapped_array' => 'prefix_wrapped_array',
    'namespace_string' => 'namespace_string',
    'namespace_number' => 'namespace_number',
    'namespace_integer' => 'namespace_integer',
    'namespace_boolean' => 'namespace_boolean',
    'namespace_array' => 'namespace_array',
    'namespace_wrapped_array' => 'namespace_wrapped_array',
    'prefix_ns_string' => 'prefix_ns_string',
    'prefix_ns_number' => 'prefix_ns_number',
    'prefix_ns_integer' => 'prefix_ns_integer',
    'prefix_ns_boolean' => 'prefix_ns_boolean',
    'prefix_ns_array' => 'prefix_ns_array',
    'prefix_ns_wrapped_array' => 'prefix_ns_wrapped_array'
} );

__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});


1;
