from pydantic import BaseModel, Field
from typing import List, Optional


class BookInfo(BaseModel):
    abstract: Optional[str] = ""
    author: Optional[str] = ""
    barcode: Optional[str] = ""
    binding: Optional[str] = ""
    category_id: Optional[int] = 0
    cover_image: Optional[str] = ""
    description: Optional[str] = ""
    edition: Optional[str] = ""
    editor: Optional[str] = ""
    format: Optional[str] = ""
    id: Optional[int] = 0
    isbn: Optional[str] = ""
    keywords: Optional[str] = ""
    language: Optional[str] = ""
    pages: Optional[int] = 0
    publication_date: Optional[int] = 0  # Unix timestamp
    publisher: Optional[str] = ""
    subject: Optional[str] = ""
    subtitle: Optional[str] = ""
    title: Optional[str] = ""
    translator: Optional[str] = ""
    weight: Optional[float] = 0.0

    class Config:
        extra = "ignore"
        exclude_none = True


class ServerDeserialize(BaseModel):
    cpu: float = 0.0
    time: float = 0.0


class MessageResponse(BaseModel):
    message: str = ""


class GeneralResponse(BaseModel):
    response_data: MessageResponse = Field(default_factory=MessageResponse)
    server_deserialize: ServerDeserialize = Field(default_factory=ServerDeserialize)
    server_protocol_total_time: float = 0.0
    server_serialize: ServerDeserialize = Field(default_factory=ServerDeserialize, alias="server_serialize")


class GetListResponse(BaseModel):
    response_data: List[BookInfo] = Field(default_factory=list)
    server_deserialize: ServerDeserialize = Field(default_factory=ServerDeserialize)
    server_protocol_total_time: float = 0.0
    server_serialize: ServerDeserialize = Field(default_factory=ServerDeserialize)
