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

use strict;

package Raritan::RPC::portsmodel::Port_2_0_4::Properties;

use Raritan::RPC::portsmodel::Port_2_0_4::DetectionMode;
use Raritan::RPC::portsmodel::Port_2_0_4::DeviceTypeWithId;
use Raritan::RPC::peripheral::PosElement_5_0_0;

sub encode {
    my ($in) = @_;
    my $encoded = {};
    $encoded->{'name'} = "$in->{'name'}";
    $encoded->{'label'} = "$in->{'label'}";
    $encoded->{'mode'} = Raritan::RPC::portsmodel::Port_2_0_4::DetectionMode::encode($in->{'mode'});
    $encoded->{'detectedDeviceType'} = "$in->{'detectedDeviceType'}";
    $encoded->{'detectedDeviceName'} = "$in->{'detectedDeviceName'}";
    $encoded->{'pinnedDeviceTypeId'} = 1 * $in->{'pinnedDeviceTypeId'};
    $encoded->{'detectedDeviceTypeId'} = 1 * $in->{'detectedDeviceTypeId'};
    $encoded->{'detectableDeviceTypes'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'detectableDeviceTypes'}}; $i0++) {
        $encoded->{'detectableDeviceTypes'}->[$i0] = Raritan::RPC::portsmodel::Port_2_0_4::DeviceTypeWithId::encode($in->{'detectableDeviceTypes'}->[$i0]);
    }
    $encoded->{'topoId'} = "$in->{'topoId'}";
    $encoded->{'serialId'} = "$in->{'serialId'}";
    $encoded->{'portType'} = 1 * $in->{'portType'};
    $encoded->{'position'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'position'}}; $i0++) {
        $encoded->{'position'}->[$i0] = Raritan::RPC::peripheral::PosElement_5_0_0::encode($in->{'position'}->[$i0]);
    }
    return $encoded;
}

sub decode {
    my ($agent, $in) = @_;
    my $decoded = {};
    $decoded->{'name'} = $in->{'name'};
    $decoded->{'label'} = $in->{'label'};
    $decoded->{'mode'} = Raritan::RPC::portsmodel::Port_2_0_4::DetectionMode::decode($agent, $in->{'mode'});
    $decoded->{'detectedDeviceType'} = $in->{'detectedDeviceType'};
    $decoded->{'detectedDeviceName'} = $in->{'detectedDeviceName'};
    $decoded->{'pinnedDeviceTypeId'} = ($in->{'pinnedDeviceTypeId'} < 7 ? $in->{'pinnedDeviceTypeId'} : 1);
    $decoded->{'detectedDeviceTypeId'} = ($in->{'detectedDeviceTypeId'} < 7 ? $in->{'detectedDeviceTypeId'} : 1);
    $decoded->{'detectableDeviceTypes'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'detectableDeviceTypes'}}; $i0++) {
        $decoded->{'detectableDeviceTypes'}->[$i0] = Raritan::RPC::portsmodel::Port_2_0_4::DeviceTypeWithId::decode($agent, $in->{'detectableDeviceTypes'}->[$i0]);
    }
    $decoded->{'topoId'} = $in->{'topoId'};
    $decoded->{'serialId'} = $in->{'serialId'};
    $decoded->{'portType'} = ($in->{'portType'} < 13 ? $in->{'portType'} : 7);
    $decoded->{'position'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'position'}}; $i0++) {
        $decoded->{'position'}->[$i0] = Raritan::RPC::peripheral::PosElement_5_0_0::decode($agent, $in->{'position'}->[$i0]);
    }
    return $decoded;
}

1;
