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

use strict;

package Raritan::RPC::event::Engine_1_0_1::Rule;

use Raritan::RPC::event::KeyValue;
use Raritan::RPC::event::Engine_1_0_1::Condition;

sub encode {
    my ($in) = @_;
    my $encoded = {};
    $encoded->{'id'} = "$in->{'id'}";
    $encoded->{'name'} = "$in->{'name'}";
    $encoded->{'isSystem'} = ($in->{'isSystem'}) ? JSON::true : JSON::false;
    $encoded->{'isEnabled'} = ($in->{'isEnabled'}) ? JSON::true : JSON::false;
    $encoded->{'isAutoRearm'} = ($in->{'isAutoRearm'}) ? JSON::true : JSON::false;
    $encoded->{'hasMatched'} = ($in->{'hasMatched'}) ? JSON::true : JSON::false;
    $encoded->{'condition'} = Raritan::RPC::event::Engine_1_0_1::Condition::encode($in->{'condition'});
    $encoded->{'actionIds'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'actionIds'}}; $i0++) {
        $encoded->{'actionIds'}->[$i0] = "$in->{'actionIds'}->[$i0]";
    }
    $encoded->{'arguments'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'arguments'}}; $i0++) {
        $encoded->{'arguments'}->[$i0] = Raritan::RPC::event::KeyValue::encode($in->{'arguments'}->[$i0]);
    }
    return $encoded;
}

sub decode {
    my ($agent, $in) = @_;
    my $decoded = {};
    $decoded->{'id'} = $in->{'id'};
    $decoded->{'name'} = $in->{'name'};
    $decoded->{'isSystem'} = ($in->{'isSystem'}) ? 1 : 0;
    $decoded->{'isEnabled'} = ($in->{'isEnabled'}) ? 1 : 0;
    $decoded->{'isAutoRearm'} = ($in->{'isAutoRearm'}) ? 1 : 0;
    $decoded->{'hasMatched'} = ($in->{'hasMatched'}) ? 1 : 0;
    $decoded->{'condition'} = Raritan::RPC::event::Engine_1_0_1::Condition::decode($agent, $in->{'condition'});
    $decoded->{'actionIds'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'actionIds'}}; $i0++) {
        $decoded->{'actionIds'}->[$i0] = $in->{'actionIds'}->[$i0];
    }
    $decoded->{'arguments'} = [];
    for (my $i0 = 0; $i0 <= $#{$in->{'arguments'}}; $i0++) {
        $decoded->{'arguments'}->[$i0] = Raritan::RPC::event::KeyValue::decode($agent, $in->{'arguments'}->[$i0]);
    }
    return $decoded;
}

1;
