//
//  FriendsApi.swift

//
//  Created by Leon on 2025/8/28.
//

import Moya

let FriendsProvider = APIConfig.useMock  && FriendsAPI.useMock
    ? MoyaProvider<FriendsAPI>(endpointClosure: myEndpointClosure, stubClosure: { target in
        let data = target.sampleData
        if data.count > 0 {
            return .delayed(seconds: 0.7)
        } else {
            return .never
        }
    })
    : MoyaProvider<FriendsAPI>(requestClosure: myRequestClosure)

enum FriendsAPI {
    static let useMock: Bool = true
    
    case heartbeatRelationList(params: [String:Any])
}

extension FriendsAPI: TargetType {
    var baseURL: URL {
        return URL(string: APIConfig.frog)!
    }

    var path: String {
        switch self {
        case .heartbeatRelationList:
            return "/web/ai-user/heartbeat-relation-list"
        }
    }

    var method: Moya.Method {
        return .post
    }

    var task: Task {
        var mParams = [String: Any]()

        switch self {
        case .heartbeatRelationList(let params):
            mParams = params
        }

        mParams.updateValue("IOS", forKey: "appClient")
        mParams.updateValue(UIDevice.UUID, forKey: "deviceCode")

        return .requestParameters(parameters: mParams, encoding: JSONEncoding.default)
    }

    var headers: [String: String]? {
        return APIConfig.apiHeaders()
    }

    var sampleData: Data {
        switch self {
        case .heartbeatRelationList:
            return Data()
        }
    }
}
