from typing import Annotated

from litestar.contrib.sqlalchemy.base import BigIntBase
from litestar.contrib.sqlalchemy.dto import SQLAlchemyDTO
from litestar.dto import DTOConfig
from sqlalchemy.orm import Mapped

from app.lib import service
from app.lib.company_owned_repository import CompanyOwnedRepository


class Machine(BigIntBase):
    __tablename__ = "machines"  # type: ignore[assignment]

    caption: Mapped[str]
    enabled: Mapped[bool]
    alive: Mapped[bool]
    deleted: Mapped[bool]
    external_id: Mapped[str]
    owner_id: Mapped[int]


class Repository(CompanyOwnedRepository[Machine]):
    model_type = Machine
    alive_flag = "alive"
    company_id_field = "owner_id"


class Service(service.Service[Machine]):
    repository_type = Repository


write_config = DTOConfig(exclude={"id"})
MachineWriteDTO = SQLAlchemyDTO[Annotated[Machine, write_config]]
MachineReadDTO = SQLAlchemyDTO[Machine]
