/*
 * Book's Story — free and open-source Material You eBook reader.
 * Copyright (C) 2024-2026 Acclorite
 * SPDX-License-Identifier: GPL-3.0-only
 */

package org.dueattendant149.bookshelf.data.mapper.history

import org.dueattendant149.bookshelf.data.local.dto.HistoryEntity
import org.dueattendant149.bookshelf.data.local.dto.HistoryWithBook
import org.dueattendant149.bookshelf.data.mapper.book.BookMapper
import org.dueattendant149.bookshelf.domain.model.history.History
import javax.inject.Inject

class HistoryMapperImpl @Inject constructor(
    private val bookMapper: BookMapper
) : HistoryMapper {
    override suspend fun toHistoryEntity(history: History): HistoryEntity {
        return HistoryEntity(
            id = history.id,
            bookId = history.book.id,
            time = history.time
        )
    }

    override suspend fun toHistory(historyWithBook: HistoryWithBook): History {
        return History(
            id = historyWithBook.history.id,
            book = bookMapper.toBook(historyWithBook.book),
            time = historyWithBook.history.time
        )
    }
}