# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright 2025 Raritan Inc. All rights reserved.
#
# This is an auto-generated file.

#
# Section generated by IdlC from "BulkRequest.idl"
#

import raritan.rpc
from raritan.rpc import Interface, Structure, ValueObject, Enumeration, typecheck, DecodeException
from raritan.rpc.opaque.bulkrpc import JsonObject

import raritan.rpc.bulkrpc


# structure
class Request(Structure):
    idlType = "bulkrpc.Request:1.0.0"
    elements = ["rid", "json"]

    def __init__(self, rid="", json=""):
        if not typecheck._is_int(rid):
            typecheck.is_string(rid, AssertionError)
        if not typecheck._is_int(json):
            typecheck.is_string(json, AssertionError)

        self.rid = rid
        self.json = json

    @classmethod
    def decode(cls, json, agent, useDefaults=False):
        obj = cls(
            rid = json['rid'] if 'rid' in json or not useDefaults else "",
            json = json['json'] if 'json' in json or not useDefaults else "",
        )
        return obj

    def encode(self):
        json = {}
        json['rid'] = str(self.rid)
        json['json'] = str(self.json)
        return json

# structure
class Response(Structure):
    idlType = "bulkrpc.Response:1.0.0"
    elements = ["json", "statcode"]

    def __init__(self, json="", statcode=0):
        if not typecheck._is_int(json):
            typecheck.is_string(json, AssertionError)
        typecheck.is_int(statcode, AssertionError)

        self.json = json
        self.statcode = statcode

    @classmethod
    def decode(cls, json, agent, useDefaults=False):
        obj = cls(
            json = json['json'] if 'json' in json or not useDefaults else "",
            statcode = json['statcode'] if 'statcode' in json or not useDefaults else 0,
        )
        return obj

    def encode(self):
        json = {}
        json['json'] = str(self.json)
        json['statcode'] = self.statcode
        return json

# interface
class BulkRequest(Interface):
    idlType = "bulkrpc.BulkRequest:1.0.2"

    # structure
    class Request(Structure):
        idlType = "bulkrpc.BulkRequest_1_0_2.Request:1.0.0"
        elements = ["rid", "json"]

        def __init__(self, rid="", json=None):
            if json is None:
                json = raritan.rpc.bulkrpc.JsonObject()
            if not typecheck._is_int(rid):
                typecheck.is_string(rid, AssertionError)

            self.rid = rid
            self.json = json

        @classmethod
        def decode(cls, json, agent, useDefaults=False):
            obj = cls(
                rid = json['rid'] if 'rid' in json or not useDefaults else "",
                json = raritan.rpc.bulkrpc.JsonObject.decode(json['json'], agent, useDefaults=useDefaults) if 'json' in json or not useDefaults else raritan.rpc.bulkrpc.JsonObject(),
            )
            return obj

        def encode(self):
            json = {}
            json['rid'] = str(self.rid)
            json['json'] = raritan.rpc.bulkrpc.JsonObject.encode(self.json)
            return json

    # structure
    class Response(Structure):
        idlType = "bulkrpc.BulkRequest_1_0_2.Response:1.0.0"
        elements = ["json", "statcode"]

        def __init__(self, json=None, statcode=0):
            if json is None:
                json = raritan.rpc.bulkrpc.JsonObject()
            typecheck.is_int(statcode, AssertionError)

            self.json = json
            self.statcode = statcode

        @classmethod
        def decode(cls, json, agent, useDefaults=False):
            obj = cls(
                json = raritan.rpc.bulkrpc.JsonObject.decode(json['json'], agent, useDefaults=useDefaults) if 'json' in json or not useDefaults else raritan.rpc.bulkrpc.JsonObject(),
                statcode = json['statcode'] if 'statcode' in json or not useDefaults else 0,
            )
            return obj

        def encode(self):
            json = {}
            json['json'] = raritan.rpc.bulkrpc.JsonObject.encode(self.json)
            json['statcode'] = self.statcode
            return json

    class _performRequest(Interface.Method):
        name = 'performRequest'

        @staticmethod
        def encode(requests):
            for x0 in requests:
                typecheck.is_struct(x0, raritan.rpc.bulkrpc.Request, AssertionError)
            args = {}
            args['requests'] = [raritan.rpc.bulkrpc.Request.encode(x0) for x0 in requests]
            return args

        @staticmethod
        def decode(rsp, agent, useDefaults=False):
            responses = [raritan.rpc.bulkrpc.Response.decode(x0, agent, useDefaults=useDefaults) for x0 in rsp['responses']]
            for x0 in responses:
                typecheck.is_struct(x0, raritan.rpc.bulkrpc.Response, DecodeException)
            return responses

    class _performBulk(Interface.Method):
        name = 'performBulk'

        @staticmethod
        def encode(requests):
            for x0 in requests:
                typecheck.is_struct(x0, raritan.rpc.bulkrpc.BulkRequest.Request, AssertionError)
            args = {}
            args['requests'] = [raritan.rpc.bulkrpc.BulkRequest.Request.encode(x0) for x0 in requests]
            return args

        @staticmethod
        def decode(rsp, agent, useDefaults=False):
            responses = [raritan.rpc.bulkrpc.BulkRequest.Response.decode(x0, agent, useDefaults=useDefaults) for x0 in rsp['responses']]
            for x0 in responses:
                typecheck.is_struct(x0, raritan.rpc.bulkrpc.BulkRequest.Response, DecodeException)
            return responses

    class _performBulkTimeout(Interface.Method):
        name = 'performBulkTimeout'

        @staticmethod
        def encode(requests, timeoutMs):
            for x0 in requests:
                typecheck.is_struct(x0, raritan.rpc.bulkrpc.BulkRequest.Request, AssertionError)
            typecheck.is_int(timeoutMs, AssertionError)
            args = {}
            args['requests'] = [raritan.rpc.bulkrpc.BulkRequest.Request.encode(x0) for x0 in requests]
            args['timeoutMs'] = timeoutMs
            return args

        @staticmethod
        def decode(rsp, agent, useDefaults=False):
            responses = [raritan.rpc.bulkrpc.BulkRequest.Response.decode(x0, agent, useDefaults=useDefaults) for x0 in rsp['responses']]
            for x0 in responses:
                typecheck.is_struct(x0, raritan.rpc.bulkrpc.BulkRequest.Response, DecodeException)
            return responses
    def __init__(self, target, agent):
        super(BulkRequest, self).__init__(target, agent)
        self.performRequest = BulkRequest._performRequest(self)
        self.performBulk = BulkRequest._performBulk(self)
        self.performBulkTimeout = BulkRequest._performBulkTimeout(self)
