from src.db.models.comic import Artist
from src.schema.comics.artist import ArtistDetailResponse


def get_artist_details(artist: Artist) -> ArtistDetailResponse:
    works = {}
    for work in artist.comic_works:
        work_type = work.work_type.name
        comic_title = work.comic.title
        if work_type in works:
            works[work_type].append(comic_title)
        else:
            works[work_type] = [comic_title]
    response = ArtistDetailResponse(
        id=artist.id,
        name=artist.name,
        works=works
    )
    return response
