//
//  MenuApi.swift
//  SodaLive
//
//  Created by klaus on 10/8/24.
//

import Foundation
import Moya

enum MenuApi {
    case getAllMenuPreset(creatorId: Int)
    case saveMenu(request: UpdateLiveMenuRequest)
}

extension MenuApi: TargetType {
    var baseURL: URL {
        return URL(string: BASE_URL)!
    }
    
    var path: String {
        switch self {
        case .getAllMenuPreset:
            return "/live/room/menu/all"
            
        case .saveMenu:
            return "/live/room/menu"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .getAllMenuPreset:
            return .get
            
        case .saveMenu:
            return .post
        }
    }
    
    var task: Moya.Task {
        switch self {
        case .getAllMenuPreset(let creatorId):
            return .requestParameters(parameters: ["creatorId" : creatorId], encoding: URLEncoding.queryString)
            
        case .saveMenu(let request):
            return .requestJSONEncodable(request)
        }
    }
    
    var headers: [String : String]? {
        return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
    }
}
