# This file was generated by mettle.genes.db.GenPy3 [ver 2.1] on Mon Feb 15 23:21:02 2021
#

import copy
import datetime
import uuid
import time
import mettle.lib
import mettle.io
import mettle.db

from .snap_msg_req_key import tSnapMsgReqKey

class tSnapMsgReq(mettle.io.ISerializable, mettle.db.IPrimaryKey):

    def __init__(self,
                 valuedate: datetime.date = datetime.date.min,
                 notype_id: str = '',
                 tot_req: int = 0,
                 tot_proc: int = 0,
                 tot_cancelled: int = 0,
                 tot_part_canc: int = 0,
                 tot_msgs: int = 0,
                 tot_msgs_sent: int = 0,
                 tot_msgs_failed: int = 0,
                 tot_msgs_retrys: int = 0):
        """
        Constructor.

        :param valuedate: datetime.date
        :param notype_id: str
        :param tot_req: int
        :param tot_proc: int
        :param tot_cancelled: int
        :param tot_part_canc: int
        :param tot_msgs: int
        :param tot_msgs_sent: int
        :param tot_msgs_failed: int
        :param tot_msgs_retrys: int
        """
        self.valuedate = valuedate
        self.notype_id = notype_id
        self.tot_req = tot_req
        self.tot_proc = tot_proc
        self.tot_cancelled = tot_cancelled
        self.tot_part_canc = tot_part_canc
        self.tot_msgs = tot_msgs
        self.tot_msgs_sent = tot_msgs_sent
        self.tot_msgs_failed = tot_msgs_failed
        self.tot_msgs_retrys = tot_msgs_retrys

    def clear(self):
        """
        Clears all member variables for this database record.
        """
        self.valuedate = datetime.date.min
        self.notype_id = ''
        self.tot_req = 0
        self.tot_proc = 0
        self.tot_cancelled = 0
        self.tot_part_canc = 0
        self.tot_msgs = 0
        self.tot_msgs_sent = 0
        self.tot_msgs_failed = 0
        self.tot_msgs_retrys = 0

    def _name(self) -> str:
        """
        Name of the record.

        :return: The name.
        """
        return 'tSnapMsgReq'

    def _serialize(self, _w: mettle.io.IWriter, _oname: str = None):
        """
        Serialize record to a stream.

        :param _w:
        :param _oname:
        """
        if _oname == None:
            _oname = self._name()

        _w.write_start(_oname)
        _w.write_date("valuedate", self.valuedate)
        _w.write_string("notype_id", self.notype_id)
        _w.write_int32("tot_req", self.tot_req)
        _w.write_int32("tot_proc", self.tot_proc)
        _w.write_int32("tot_cancelled", self.tot_cancelled)
        _w.write_int32("tot_part_canc", self.tot_part_canc)
        _w.write_int32("tot_msgs", self.tot_msgs)
        _w.write_int32("tot_msgs_sent", self.tot_msgs_sent)
        _w.write_int32("tot_msgs_failed", self.tot_msgs_failed)
        _w.write_int32("tot_msgs_retrys", self.tot_msgs_retrys)
        _w.write_end(_oname)

    def _deserialize(self, _r: mettle.io.IReader, _oname: str = None):
        """
        Deserialize record from a stream.

        :param _r:
        :param _oname:
        """
        if _oname == None:
            _oname = self._name()

        _r.read_start(_oname)
        self.valuedate = _r.read_date("valuedate")
        self.notype_id = _r.read_string("notype_id")
        self.tot_req = _r.read_int32("tot_req")
        self.tot_proc = _r.read_int32("tot_proc")
        self.tot_cancelled = _r.read_int32("tot_cancelled")
        self.tot_part_canc = _r.read_int32("tot_part_canc")
        self.tot_msgs = _r.read_int32("tot_msgs")
        self.tot_msgs_sent = _r.read_int32("tot_msgs_sent")
        self.tot_msgs_failed = _r.read_int32("tot_msgs_failed")
        self.tot_msgs_retrys = _r.read_int32("tot_msgs_retrys")
        _r.read_end(_oname)

    def _copy_from(self, rec: "tSnapMsgReq"):
        """
        Copies the column from the rec into this record.

        :param rec: The source record.
        """
        self.valuedate = rec.valuedate
        self.notype_id = rec.notype_id
        self.tot_req = rec.tot_req
        self.tot_proc = rec.tot_proc
        self.tot_cancelled = rec.tot_cancelled
        self.tot_part_canc = rec.tot_part_canc
        self.tot_msgs = rec.tot_msgs
        self.tot_msgs_sent = rec.tot_msgs_sent
        self.tot_msgs_failed = rec.tot_msgs_failed
        self.tot_msgs_retrys = rec.tot_msgs_retrys

    def _write_pk(self, _key: "tSnapMsgReq"):
        """
        Write the primary key columns to the key object.

        :param _key:
        """
        self._write_key(_key)

    def _read_pk(self, _key: "tSnapMsgReq"):
        """
        Read the primary key columns from the key object.

        :param _key:
        """
        self._read_key(_key)

    def _serialize_key(self, _w: mettle.io.IWriter):
        """
        Serialize the primary key to a stream.

        :param _w:
        """
        _key = tSnapMsgReqKey()

        self._write_key(_key)
        _key._serialize(_w)

    def _deserialize_key(self, _r: mettle.io.IReader):
        """
        Deserialize the primary key from a stream.

        :param _r:
        """
        _key = tSnapMsgReqKey()

        _key._deserialize(_r)
        self._read_key(_key)

    @staticmethod
    def _cache_davs(dvc=None, for_ins: bool = False, key_only: bool = False):
        """
        Cache the DAV into the dav cache (or create one) and return it.

        :param dvc: (mettle.lib.DavCache), target cache, if None a new one is created and returned.
        :param for_ins: Davs for insert.
        :param key_only: Davs by key only, ie for delete/selectone.
        """
        if dvc is None:
            dvc = mettle.lib.DavCache()

        dvc.add_targ("valuedate", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("notype_id", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("notype_id", mettle.lib.Dav(mettle.lib.Dav.eDavType.Max, 64))
        if key_only:
            return dvc

        dvc.add_targ("tot_req", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_proc", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_cancelled", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_part_canc", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_msgs", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_msgs_sent", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_msgs_failed", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))
        dvc.add_targ("tot_msgs_retrys", mettle.lib.Dav(mettle.lib.Dav.eDavType.NotNull))

        return dvc

    def _get_davs(self, dvc=None, for_ins: bool = False, key_only: bool = False):
        tSnapMsgReq._cache_davs(dvc, for_ins, key_only)

    def _write_key(self, _key: tSnapMsgReqKey):
        """
        Write primary key columns to _key.

        :param _key:
        """
        _key.valuedate = self.valuedate
        _key.notype_id = self.notype_id

    def _read_key(self, _key: tSnapMsgReqKey):
        """
        Read the primary key columns from _key.

        :param _key:
        """
        self.valuedate = _key.valuedate
        self.notype_id = _key.notype_id

    @staticmethod
    def _pk_compare(x, y) -> int:
        """
        Compare function do primary key comparisons for list sorts and searches.

        :return: zero for x == y, negative for x < y, positive for x > y
        """
        rc = (x.valuedate > y.valuedate) - (x.valuedate < y.valuedate)

        if rc != 0:
            return rc

        rc = (x.notype_id > y.notype_id) - (x.notype_id < y.notype_id)

        return rc

    def __lt__(self, other):
        return other and self._pk_compare(self, other) < 0

    def __gt__(self, other):
        return other and self._pk_compare(self, other) > 0

    def __eq__(self, other):
        return other and self._pk_compare(self, other) == 0

    def __le__(self, other):
        return other and self._pk_compare(self, other) <= 0

    def __ge__(self, other):
        return other and self._pk_compare(self, other) >= 0

    def __ne__(self, other):
        return other == None or self._pk_compare(self, other)

    def __repr__(self) -> str:
        return '<SnapMsgReq [valuedate:%s, notype_id:%.32s, tot_req:%r, tot_proc:%r, tot_cancelled:%r, tot_part_canc:%r, tot_msgs:%r, tot_msgs_sent:%r, tot_msgs_failed:%r, tot_msgs_retrys:%r]>' % (
            self.valuedate, self.notype_id, self.tot_req, self.tot_proc, self.tot_cancelled, self.tot_part_canc, self.tot_msgs, self.tot_msgs_sent, self.tot_msgs_failed, self.tot_msgs_retrys)


    class List(list, mettle.io.ISerializable):
        """
        List Class
        """

        def _name(self) -> str:
            """
            Name of the list.

            :return: The name
            """
            return 'tSnapMsgReq.List'

        def _serialize(self, _w: mettle.io.IWriter, _oname: str = None):
            """
            Serialize the list to a stream.

            :param _w:
            :param _oname:
            """
            if _oname == None:
                _oname = self._name()

            _w.write_start_list(_oname, len(self))

            for _rec in self:
                _rec._serialize(_w)

            _w.write_end(_oname)

        def _deserialize(self, _r: mettle.io.IReader, _oname: str = None):
            """
            Deserialize the list from a stream.

            :param _r:
            :param _oname:
            """
            if _oname == None:
                _oname = self._name()

            _cnt = _r.read_start_list(_oname)

            while _cnt >= 1:
                _rec  = tSnapMsgReq()
                _cnt -= 1
                _rec._deserialize(_r)
                self.append(_rec)

            _r.read_end(_oname)

        def __repr__(self) -> str:
            return '<tSnapMsgReq.List[%d]>' % (len(self))

        def _get_davs(self, dvc=None, for_ins: bool = False, key_only: bool = False):
            return tSnapMsgReq._cache_davs(dvc, for_ins, key_only)

