//
//  LiveRecommendApi.swift
//  SodaLive
//
//  Created by klaus on 2023/08/09.
//

import Foundation
import Moya

enum LiveRecommendApi {
    case getFollowedCreatorAllList(page: Int, size: Int)
    case getFollowedChannelList
    case getRecommendChannelList
    case getRecommendLive
}

extension LiveRecommendApi: TargetType {
    var baseURL: URL {
        return URL(string: BASE_URL)!
    }
    
    var path: String {
        switch self {
        case .getFollowedCreatorAllList:
            return "/live/recommend/following/channel/all/list"
            
        case .getFollowedChannelList:
            return "/live/recommend/following/channel/list"
            
        case .getRecommendChannelList:
            return "/live/recommend/channel"
            
        case .getRecommendLive:
            return "/live/recommend"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .getFollowedCreatorAllList,
                .getFollowedChannelList,
                .getRecommendChannelList,
                .getRecommendLive:
            return .get
        }
    }
    
    var task: Moya.Task {
        switch self {
        case .getFollowedChannelList,
                .getRecommendChannelList,
                .getRecommendLive:
            return .requestPlain
            
        case .getFollowedCreatorAllList(let page, let size):
            let parameters = [
                "page": page - 1,
                "size": size,
                "timezone": TimeZone.current.identifier,
            ] as [String : Any]
            
            return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
        }
    }
    
    var headers: [String : String]? {
        return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
    }
}
