import { ChapterRepositoryInterface } from '../../domain/repository/ChapterRepositoryInterface';

export class ApiChapterRepository extends ChapterRepositoryInterface {
    async getChapter(chapterId) {
        const response = await fetch(`/api/reader/chapter/${chapterId}`);
        if (!response.ok) {
            throw new Error('Failed to fetch chapter');
        }
        return response.json();
    }

    async getChapterPages(chapterId, page = 1, itemsPerPage = 9999) {
        const response = await fetch(
            `/api/reader/chapter/${chapterId}/pages?page=${page}&itemsPerPage=${itemsPerPage}`
        );
        if (!response.ok) {
            throw new Error('Failed to fetch chapter pages');
        }
        return response.json();
    }
}
