from datetime import datetime
from typing import Optional

from pydantic import BaseModel

from src.db.models.comic import Issue


class IssueResponse(BaseModel):
    id: str
    created_date: datetime
    last_modified_date: datetime
    version: int
    issue_number: str
    title: Optional[str]
    published_on: Optional[datetime]
    in_stock: bool
    is_read: bool
    comic_id: str
    volume_id: Optional[str]
    story_arc_id: Optional[str]

def issue_to_response(issue: Issue) -> IssueResponse:
    response: IssueResponse = IssueResponse(
        id=issue.id,
        created_date=issue.created_date,
        last_modified_date=issue.last_modified_date,
        version=issue.version,
        issue_number=issue.issue_number,
        title=issue.title,
        published_on=issue.published_on,
        in_stock=issue.in_stock,
        is_read=issue.is_read,
        comic_id=issue.comic_id,
        volume_id=issue.volume_id,
        story_arc_id=issue.story_arc_id
    )
    return response
