from sqlalchemy import Column, String, ForeignKey, Integer
from sqlalchemy.orm import relationship

from xplordb.datamodel.company import Company
from xplordb.sqlalchemy.base import Base


class XplordbCompanyTable(Company, Base):
    """
    Define spatialite columns for Company definition
    """
    __tablename__ = "company"
    __table_args__ = {"schema": 'ref'}

    name = Column("name", String, primary_key = True)

    persons = relationship("XplordbPersonTable", back_populates="company_rel")


    def to_company(self) -> Company:

        return Company(name=self.name)