//
//  SmallRobotAPI.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/2.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit
import Moya
import HandyJSON
import SwiftyJSON

let SmallRobotProvider = MoyaProvider<SmallRobotAPI>()

enum SmallRobotAPI {
    case smallRobotToken(value:String,pageNum:Int)
    case smallRobotDialogue(value:String)
}
extension SmallRobotAPI: TargetType {
    var baseURL: URL {
        return URL(string: "https://aip.baidubce.com")!
    }
    
    var path: String {
        switch self {
        case .smallRobotDialogue: return "/rpc/2.0/unit/service/chat"
        case .smallRobotToken: return "/oauth/2.0/token"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .smallRobotDialogue: return .post
        case .smallRobotToken: return .get
        }
    }
    
    var sampleData: Data { return "".data(using: String.Encoding.utf8)! }
    var headers: [String : String]? {
        return ["Content-type":"application/json;charset=utf-8"]
    }
    
    var task: Task {
        var parmeters:[String:Any] = [:]
        switch self {
        case .smallRobotToken( _,  _):
            parmeters["grant_type"] = "client_credentials"
            parmeters["client_id"] = "1MZasDCVcHQBi8TOfvDmszDb"
            parmeters["client_secret"] = "7IhCxG7BhunGG6mgllchq6cUBLoduWKQ"
        case .smallRobotDialogue( _):
            parmeters["version"] = "2.0"
            parmeters["service_id"] = "S19966"
            parmeters["skill_ids"] = []
            parmeters["log_id"] = AccountInfo.sharedInstance().appUUID
            parmeters["session_id"] = "上一次请求"
            var request:[String:Any] = [:]
            request["user_id"] = "用户id"
            request["query"] = "文本"
            parmeters["request"] = request
            parmeters["service_id"] = "18783853"
//            SYS_REMEMBERED_SKILLS = [skill_ids]
        }
//        return .requestData(jsonToData(jsonDic: parmeters)!)
        return .requestParameters(parameters: parmeters, encoding: URLEncoding.default)
    }
    


}
