<reponame>not-decided-yet/parky-server<gh_stars>0
from datetime import datetime

from pydantic import BaseModel
from sqlalchemy import Boolean, Column, DateTime, Float, Integer, String, Text

from .database import Base


class User(Base):
    __tablename__ = "users"

    uid = Column(Integer, primary_key=True, index=True)
    name = Column(String(length=100))
    ssn = Column(String(length=14))
    firebase_token = Column(Text)
    user_id = Column(String(length=30))
    password = Column(String(length=30))
    public_key = Column(Text)
    car_number = Column(String(length=10), default="N/A")

    created_at = Column(DateTime, default=datetime.now)

    def as_dict(self):
        """
        Convert to appropriate dictionary structure.
        """
        return {
            "uid": self.uid,
            "name": self.name,
            "ssn": self.ssn,
            "user_id": self.user_id,
            "public_key": self.public_key,
            # Password is not provided
            "created_at": self.created_at,
        }


class ParkingLot(Base):
    __tablename__ = "parking_lots"

    _id = Column(Integer, primary_key=True, index=True)
    name = Column(String(length=100))
    longitude = Column(Float)
    latitude = Column(Float)
    is_free = Column(Boolean)
    lots_status = Column(Text)
    lots_number = Column(Text)
    priority = Column(Text)

    created_at = Column(DateTime, default=datetime.now)

    def as_dict(self):
        """
        Convert to appropriate dictionary structure.
        """
        return {
            "_id": self._id,
            "name": self.name,
            "longitude": self.longitude,
            "latitude": self.latitude,
            "is_free": self.is_free,
            "lots_status": self.lots_status.split(","),
            "lots_number": self.lots_number.split(","),
            "priority": [int(i) for i in self.priority.split(",")],
            "created_at": self.created_at,
        }


class Vehicle(BaseModel):
    """
    Data Type for vehicle.
    """

    #: Plate number
    number: str
    #: Public key
    public_key: str
