# -*- coding: utf-8 -*-

from datetime import datetime
from typing import Optional

from sqlmodel import Column, DateTime, Field, Relationship, SQLModel


class Device(SQLModel, table=True):  # type: ignore
    """The Device model.

    It is used to model a device.
    """

    # setup the primary key of the table
    uuid: str = Field(primary_key=True)

    # setup the columns / properties
    name: Optional[str]
    type: Optional[str]
    arch: Optional[str]
    cpid: Optional[str]
    cpu_type: Optional[str]
    cpu_architecture: Optional[str]
    cpu_features: Optional[str]
    processor_count: Optional[int]
    coprocessor_count: Optional[int]
    product_name: Optional[str]
    floating_point_speed: Optional[float]
    integer_speed: Optional[float]
    total_disk_space: Optional[float]
    free_disk_space: Optional[float]
    swap_space: Optional[float]
    domain_name: Optional[str]
    operating_system_version: Optional[str]
    boinc_version: Optional[str]
    scitizen_version: Optional[str]
    platform: Optional[str]

    # setup the pseudo-columns (metadata related to the record)
    created_at: Optional[datetime] = Field(
        sa_column=Column(DateTime(), default=datetime.utcnow, name="_created_at")
    )
    updated_at: Optional[datetime] = Field(
        sa_column=Column(DateTime(), onupdate=datetime.utcnow, name="_updated_at")
    )


class Project(SQLModel, table=True):  # type: ignore
    """The Project model.

    It is used to model a project.
    """

    # setup the primary key of the table
    uuid: str = Field(primary_key=True)

    # setup the columns / properties
    name: Optional[str]
    avatar: Optional[str]
    description: Optional[str]
    general_area: Optional[str]
    home: Optional[str]
    image: Optional[str]
    is_active: Optional[bool] = True
    keywords: Optional[str]
    name: Optional[str]  # type: ignore
    platforms: Optional[str]
    specific_area: Optional[str]
    summary: Optional[str]
    url: Optional[str]
    web_url: Optional[str]
    weak_authenticator: Optional[str]

    # setup the pseudo-columns (metadata related to the record)
    created_at: Optional[datetime] = Field(
        sa_column=Column(DateTime(), default=datetime.utcnow, name="_created_at")
    )
    updated_at: Optional[datetime] = Field(
        sa_column=Column(DateTime(), onupdate=datetime.utcnow, name="_updated_at")
    )

    # setup the relationship
    task: Optional["Task"] = Relationship(back_populates="project_rel")


class Task(SQLModel, table=True):  # type: ignore
    """The Task model.

    It is used to model a task.
    """

    # setup the primary key of the table
    uuid: str = 