//
//  ExplorerApi.swift
//  SodaLive
//
//  Created by klaus on 2023/08/10.
//

import Foundation
import Moya

enum ExplorerApi {
    case getExplorer
    case searchChannel(channel: String)
}

extension ExplorerApi: TargetType {
    var baseURL: URL {
        return URL(string: BASE_URL)!
    }
    
    var path: String {
        switch self {
        case .getExplorer:
            return "/explorer"
            
        case .searchChannel:
            return "/explorer/search/channel"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .getExplorer, .searchChannel:
            return .get
        }
    }
    
    var task: Task {
        switch self {
        case .getExplorer:
            return .requestPlain
            
        case .searchChannel(let channel):
            return .requestParameters(parameters: ["channel" : channel], encoding: URLEncoding.queryString)
        }
    }
    
    var headers: [String : String]? {
        return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
    }
}
