# This file is part of HYDRA - cross-platform remote administration
# system for 1C:Enterprise (https://github.com/vbondarevsky/hydra_agent).
# Copyright (C) 2017  Vladimir Bondarevskiy.
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


class InfoBase:
    id = ""
    name = ""
    description = ""

    def __init__(self, session_id, cluster):
        self.id = session_id.strip()
        self.cluster = cluster

    def __eq__(self, other):
        return self.__dict__ == other.__dict__

    def __repr__(self):
        return f"<InfoBase(id={self.id}, name={self.name}, cluster={self.cluster})>"

    @staticmethod
    def from_dict(params, cluster):
        infobase = InfoBase(params["infobase"], cluster)
        infobase.name = params["name"]
        infobase.description = params["descr"]
        return infobase

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "description": self.description,
            "cluster": self.cluster.to_dict(),
        }
