# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright 2023 Raritan Inc. All rights reserved.
#
# This file was generated by IdlC from PeripheralDeviceSlot.idl.

use strict;

package Raritan::RPC::peripheral::DeviceSlot_3_0_0::Settings;

use Raritan::RPC::peripheral::DeviceSlot_3_0_0::Location;

sub encode {
    my ($in) = @_;
    my $encoded = {};
    $encoded->{'name'} = "$in->{'name'}";
    $encoded->{'description'} = "$in->{'description'}";
    $encoded->{'location'} = Raritan::RPC::peripheral::DeviceSlot_3_0_0::Location::encode($in->{'location'});
    $encoded->{'useDefaultThresholds'} = ($in->{'useDefaultThresholds'}) ? JSON::true : JSON::false;
    $encoded->{'properties'} = [];
    foreach my $key0 (keys %{$in->{'properties'}}) {
        my $value0 = $in->{'properties'}->{$key0};
        my $elem0 = {};
        $elem0->{'key'} = "$key0";
        $elem0->{'value'} = "$value0";
        push(@{$encoded->{'properties'}}, $elem0);
    }
    return $encoded;
}

sub decode {
    my ($agent, $in) = @_;
    my $decoded = {};
    $decoded->{'name'} = $in->{'name'};
    $decoded->{'description'} = $in->{'description'};
    $decoded->{'location'} = Raritan::RPC::peripheral::DeviceSlot_3_0_0::Location::decode($agent, $in->{'location'});
    $decoded->{'useDefaultThresholds'} = ($in->{'useDefaultThresholds'}) ? 1 : 0;
    $decoded->{'properties'} = {};
    for (my $i0 = 0; $i0 <= $#{$in->{'properties'}}; $i0++) {
        my $key0 = $in->{'properties'}->[$i0]->{'key'};
        my $value0 = $in->{'properties'}->[$i0]->{'value'};
        $decoded->{'properties'}->{$key0} = $value0;
    }
    return $decoded;
}

1;
