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

use strict;

package Raritan::RPC::peripheral::DeviceManager_5_0_1::Settings;

use Raritan::RPC::sensors::NumericSensor_4_0_5::Thresholds;

sub encode {
    my ($in) = @_;
    my $encoded = {};
    $encoded->{'zCoordMode'} = 1 * $in->{'zCoordMode'};
    $encoded->{'autoManageNewDevices'} = ($in->{'autoManageNewDevices'}) ? JSON::true : JSON::false;
    $encoded->{'deviceAltitude'} = 1 * $in->{'deviceAltitude'};
    $encoded->{'presenceDetectionTimeout'} = 1 * $in->{'presenceDetectionTimeout'};
    $encoded->{'defaultThresholdsMap'} = [];
    foreach my $key0 (keys %{$in->{'defaultThresholdsMap'}}) {
        my $value0 = $in->{'defaultThresholdsMap'}->{$key0};
        my $elem0 = {};
        $elem0->{'key'} = "$key0";
        $elem0->{'value'} = Raritan::RPC::sensors::NumericSensor_4_0_5::Thresholds::encode($value0);
        push(@{$encoded->{'defaultThresholdsMap'}}, $elem0);
    }
    $encoded->{'maxActivePoweredDryContacts'} = 1 * $in->{'maxActivePoweredDryContacts'};
    $encoded->{'muteOtherAccessControlUnit'} = ($in->{'muteOtherAccessControlUnit'}) ? JSON::true : JSON::false;
    return $encoded;
}

sub decode {
    my ($agent, $in) = @_;
    my $decoded = {};
    $decoded->{'zCoordMode'} = $in->{'zCoordMode'};
    $decoded->{'autoManageNewDevices'} = ($in->{'autoManageNewDevices'}) ? 1 : 0;
    $decoded->{'deviceAltitude'} = $in->{'deviceAltitude'};
    $decoded->{'presenceDetectionTimeout'} = $in->{'presenceDetectionTimeout'};
    $decoded->{'defaultThresholdsMap'} = {};
    for (my $i0 = 0; $i0 <= $#{$in->{'defaultThresholdsMap'}}; $i0++) {
        my $key0 = $in->{'defaultThresholdsMap'}->[$i0]->{'key'};
        my $value0 = Raritan::RPC::sensors::NumericSensor_4_0_5::Thresholds::decode($agent, $in->{'defaultThresholdsMap'}->[$i0]->{'value'});
        $decoded->{'defaultThresholdsMap'}->{$key0} = $value0;
    }
    $decoded->{'maxActivePoweredDryContacts'} = $in->{'maxActivePoweredDryContacts'};
    $decoded->{'muteOtherAccessControlUnit'} = ($in->{'muteOtherAccessControlUnit'}) ? 1 : 0;
    return $decoded;
}

1;
