# Do NOT edit this file!
# It was generated by IdlC class idl.json.python.ProxyAsnVisitor.

#
# Section generated from "/home/nb/builds/MEGA/px2-3.0.0-3.0.9-branch-20140613-none-release-none-pdu-raritan/fwcomponents/mkdist/tmp/px2_final/libisys/src/idl/DateTime.idl"
#

import raritan.rpc
from raritan.rpc import (
    Interface,
    Structure,
    ValueObject,
    Enumeration,
    typecheck,
    DecodeException,
)
import raritan.rpc.datetime


# interface
class DateTime(Interface):
    idlType = "datetime.DateTime:2.0.0"

    # structure
    class ZoneInfo(Structure):
        idlType = "datetime.DateTime.ZoneInfo:1.0.0"
        elements = ["id", "name", "hasDSTInfo"]

        def __init__(self, id, name, hasDSTInfo):
            typecheck.is_int(id, AssertionError)
            typecheck.is_string(name, AssertionError)
            typecheck.is_bool(hasDSTInfo, AssertionError)

            self.id = id
            self.name = name
            self.hasDSTInfo = hasDSTInfo

        @classmethod
        def decode(cls, json, agent):
            obj = cls(
                id=json["id"],
                name=json["name"],
                hasDSTInfo=json["hasDSTInfo"],
            )
            return obj

        def encode(self):
            json = {}
            json["id"] = self.id
            json["name"] = self.name
            json["hasDSTInfo"] = self.hasDSTInfo
            return json

    # structure
    class ZoneCfg(Structure):
        idlType = "datetime.DateTime.ZoneCfg:1.0.0"
        elements = ["id", "name", "enableAutoDST"]

        def __init__(self, id, name, enableAutoDST):
            typecheck.is_int(id, AssertionError)
            typecheck.is_string(name, AssertionError)
            typecheck.is_bool(enableAutoDST, AssertionError)

            self.id = id
            self.name = name
            self.enableAutoDST = enableAutoDST

        @classmethod
        def decode(cls, json, agent):
            obj = cls(
                id=json["id"],
                name=json["name"],
                enableAutoDST=json["enableAutoDST"],
            )
            return obj

        def encode(self):
            json = {}
            json["id"] = self.id
            json["name"] = self.name
            json["enableAutoDST"] = self.enableAutoDST
            return json

    # enumeration
    class Protocol(Enumeration):
        idlType = "datetime.DateTime.Protocol:1.0.0"
        values = ["STATIC", "NTP"]

    Protocol.STATIC = Protocol(0)
    Protocol.NTP = Protocol(1)

    # structure
    class NtpCfg(Structure):
        idlType = "datetime.DateTime.NtpCfg:1.0.0"
        elements = ["forceStatic", "server1", "server2"]

        def __init__(self, forceStatic, server1, server2):
            typecheck.is_bool(forceStatic, AssertionError)
            typecheck.is_string(server1, AssertionError)
            typecheck.is_string(server2, AssertionError)

            self.forceStatic = forceStatic
            self.server1 = server1
            self.server2 = server2

        @classmethod
        def decode(cls, json, agent):
            obj = cls(
                forceStatic=json["forceStatic"],
                server1=json["server1"],
                server2=json["server2"],
            )
            return obj

        def encode(self):
            json = {}
            json["forceStatic"] = self.forceStatic
            json["server1"] = self.server1
            json["server2"] = self.server2
            return json

    # structure
    class Cfg(Structure):
        idlType = "datetime.DateTime.Cfg:1.0.0"
        elements = ["zoneCfg", "protocol", "deviceTime", "ntpCfg"]

        def __init__(self, zoneCfg, protocol, deviceTime, ntpCfg):
            typecheck.is_struct(
                zoneCfg, raritan.rpc.datetime.DateTime.ZoneCfg, AssertionError
            )
            typecheck.is_enum(
                protocol, raritan.rpc.datetime.DateTime.Protocol, AssertionError
            )
            typecheck.is_time(deviceTime, AssertionError)
            typecheck.is_struct(
                ntpCfg, raritan.rpc.datetime.DateTime.NtpCfg, AssertionError
            )

            self.zoneCfg = zoneCfg
            self.protocol = protocol
            self.deviceTime = deviceTime
            self.ntpCfg = ntpCfg

        @classmethod
        def decode(cls, json, agent):
            obj = cls(
                zoneCfg=raritan.rpc.datetime.DateTime.ZoneCfg.decode(
                    json["zoneCfg"], agent
                ),
                protocol=raritan.rpc.datetime.DateTime.Protocol.decode(
                    json["protocol"]
                ),
                deviceTime=raritan.rpc.Time.decode(json["deviceTime"]),
                ntpCfg=raritan.rpc.datetime.DateTime.NtpCfg.decode(
                    json["ntpCfg"], agent
                ),
            )
            return obj

        def encode(self):
            json = {}
            json["zoneCfg"] = raritan.rpc.datetime.DateTime.ZoneCfg.encode(self.zoneCfg)
            json["protocol"] = raritan.rpc.datetime.DateTime.Protocol.encode(
                self.protocol
            )
            json["deviceTime"] = raritan.rpc.Time.encode(self.deviceTime)
            json["ntpCfg"] = raritan.rpc.datetime.DateTime.NtpCfg.encode(self.ntpCfg)
            return json

    def getZoneInfos(self, useOlson):
        agent = self.agent
        typecheck.is_bool(useOlson, AssertionError)
        args = {}
        args["useOlson"] = useOlson
        rsp = agent.json_rpc(self.target, "getZoneInfos", args)
        zoneInfos = [
            raritan.rpc.datetime.DateTime.ZoneInfo.decode(x0, agent)
            for x0 in rsp["zoneInfos"]
        ]
        for x0 in zoneInfos:
            typecheck.is_struct(
                x0, raritan.rpc.datetime.DateTime.ZoneInfo, DecodeException
            )
        return zoneInfos

    def checkNtpServer(self, ntpServer):
        agent = self.agent
        typecheck.is_string(ntpServer, AssertionError)
        args = {}
        args["ntpServer"] = ntpServer
        rsp = agent.json_rpc(self.target, "checkNtpServer", args)
        _ret_ = rsp["_ret_"]
        typecheck.is_bool(_ret_, DecodeException)
        return _ret_

    def getCfg(self):
        agent = self.agent
        args = {}
        rsp = agent.json_rpc(self.target, "getCfg", args)
        cfg = raritan.rpc.datetime.DateTime.Cfg.decode(rsp["cfg"], agent)
        typecheck.is_struct(cfg, raritan.rpc.datetime.DateTime.Cfg, DecodeException)
        return cfg

    def setCfg(self, cfg):
        agent = self.agent
        typecheck.is_struct(cfg, raritan.rpc.datetime.DateTime.Cfg, AssertionError)
        args = {}
        args["cfg"] = raritan.rpc.datetime.DateTime.Cfg.encode(cfg)
        rsp = agent.json_rpc(self.target, "setCfg", args)
        _ret_ = rsp["_ret_"]
        typecheck.is_int(_ret_, DecodeException)
        return _ret_

    def getTime(self, useOlson):
        agent = self.agent
        typecheck.is_bool(useOlson, AssertionError)
        args = {}
        args["useOlson"] = useOlson
        rsp = agent.json_rpc(self.target, "getTime", args)
        zone = raritan.rpc.datetime.DateTime.ZoneInfo.decode(rsp["zone"], agent)
        dstEnabled = rsp["dstEnabled"]
        utcOffset = rsp["utcOffset"]
        currentTime = raritan.rpc.Time.decode(rsp["currentTime"])
        typecheck.is_struct(
            zone, raritan.rpc.datetime.DateTime.ZoneInfo, DecodeException
        )
        typecheck.is_bool(dstEnabled, DecodeException)
        typecheck.is_int(utcOffset, DecodeException)
        typecheck.is_time(currentTime, DecodeException)
        return (zone, dstEnabled, utcOffset, currentTime)
