//
//  SeriesRepository.swift
//  SodaLive
//
//  Created by klaus on 4/29/24.
//

import Foundation
import CombineMoya
import Combine
import Moya

class SeriesRepository {
    private let api = MoyaProvider<SeriesApi>()
    
    func getSeriesList(creatorId: Int, sortType: SeriesListAllViewModel.SeriesSortType, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getSeriesList(creatorId: creatorId, sortType: sortType, page: page, size: size))
    }
    
    func getSeriesDetail(seriesId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getSeriesDetail(seriesId: seriesId))
    }
    
    func getSeriesContentList(seriesId: Int, page: Int, size: Int, sortType: SeriesListAllViewModel.SeriesSortType) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getSeriesContentList(seriesId: seriesId, page: page, size: size, sortType: sortType))
    }
    
    func getRecommendSeriesList() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(
            .getRecommendSeriesList(
                isAdultContentVisible: UserDefaults.isAdultContentVisible(),
                contentType: ContentType(rawValue: UserDefaults.string(forKey: .contentPreference)) ?? ContentType.ALL
            )
        )
    }
}
