"""All Models for database are defined here"""
from typing import Optional, List
from sqlalchemy import Column, ForeignKey, Integer
from sqlmodel import Field, SQLModel, Relationship


class VrfLink(SQLModel, table=True):
    """Used for vrf to device link"""
    vrf_id: Optional[int] = Field(default=None, foreign_key="vrf.id", primary_key=True)
    device_id: Optional[int] = Field(
        default=None, foreign_key="device.id", primary_key=True
    )


class Platform(SQLModel, table=True):
    """Used to define platforms"""
    id: Optional[int] = Field(default=None, primary_key=True)
    platform_name: str = Field(index=True)


class Vrf(SQLModel, table=True):
    """used to define VRFs"""
    id: Optional[int] = Field(default=None, primary_key=True)
    vrf_name: str = Field(index=True)
    devices: List["Device"] = Relationship(back_populates="vrfs", link_model=VrfLink)


class Device(SQLModel, table=True):
    """Used to define a simple device"""
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str = Field(index=True)
    mgmt: str
    platform_id: Optional[int] = Field(
        sa_column=Column(
            Integer, ForeignKey("platform.id", ondelete="SET NULL", onupdate="CASCADE")
        )
    )
    vrfs: List["Vrf"] = Relationship(back_populates="devices", link_model=VrfLink)

sqlmodel.Field sqlalchemy.ForeignKey sqlmodel.Relationship
[((288, 347), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'foreign_key': '"""vrf.id"""', 'primary_key': '(True)'}), "(default=None, foreign_key='vrf.id', primary_key=True)\n", (293, 347), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((379, 441), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'foreign_key': '"""device.id"""', 'primary_key': '(True)'}), "(default=None, foreign_key='device.id', primary_key=True)\n", (384, 441), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((555, 592), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (560, 592), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((618, 635), 'sqlmodel.Field', 'Field', ([], {'index': '(True)'}), '(index=True)\n', (623, 635), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((725, 762), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (730, 762), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((783, 800), 'sqlmodel.Field', 'Field', ([], {'index': '(True)'}), '(index=True)\n', (788, 800), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((831, 886), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""vrfs"""', 'link_model': 'VrfLink'}), "(back_populates='vrfs', link_model=VrfLink)\n", (843, 886), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((990, 1027), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (995, 1027), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((1044, 1061), 'sqlmodel.Field', 'Field', ([], {'index': '(True)'}), '(index=True)\n', (1049, 1061), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((1270, 1328), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""devices"""', 'link_model': 'VrfLink'}), "(back_populates='devices', link_model=VrfLink)\n", (1282, 1328), False, 'from sqlmodel import Field, SQLModel, Relationship\n'), ((1163, 1229), 'sqlalchemy.ForeignKey', 'ForeignKey', (['"""platform.id"""'], {'ondelete': '"""SET NULL"""', 'onupdate': '"""CASCADE"""'}), "('platform.id', ondelete='SET NULL', onupdate='CASCADE')\n", (1173, 1229), False, 'from sqlalchemy import Column, ForeignKey, Integer\n')]