from ..base import BaseModel
from .encoded_text_chunk import EncodedTextChunk


class ModelInput(BaseModel):
    chunks: list[EncodedTextChunk]

    @classmethod
    def from_ints(cls, tokens: list[int]) -> "ModelInput":
        return cls(chunks=[EncodedTextChunk(tokens=tokens)])

    def to_ints(self) -> list[int]:
        return [token for chunk in self.chunks for token in chunk.tokens]

    def tolist(self) -> list[int]:
        return self.to_ints()

    @property
    def length(self) -> int:
        return len(self)

    def __len__(self) -> int:
        return sum([len(chunk) for chunk in self.chunks])
