from typing import List

from src.db.models.comic import Publisher
from src.schema.comics.comic import ComicResponse
from src.schema.comics.publisher import PublisherResponse
from src.schema.comics.publisher_details import PublisherDetailsResponse


def get_publisher_details(publisher: Publisher) -> PublisherDetailsResponse:
    imprints: List[PublisherResponse] = []
    for imprint in publisher.imprints:
        imprints.append(PublisherResponse(id=imprint.id, name=str(imprint.name)))
    comics: List[ComicResponse] = []
    for comic in publisher.comics:
        comics.append(
            ComicResponse(id=comic.id, title=comic.title, completed=comic.completed)
        )
    parent_publisher: PublisherResponse | None = None
    if publisher.parent_publisher:
        parent_publisher = PublisherResponse(id=publisher.parent_publisher.id, name=str(publisher.parent_publisher.name))
    response: PublisherDetailsResponse = PublisherDetailsResponse(
        id=publisher.id, name=str(publisher.name), parent_publisher=parent_publisher, imprints=imprints, comics=comics
    )
    return response
