package com.fastbee.http.ruleEngine;

import com.dtflys.forest.http.ForestResponse;
import com.fastbee.http.client.Amap;
import com.fastbee.http.client.Cn12306;
import com.fastbee.http.client.Gitee;
import com.fastbee.http.client.Yunchache;
import com.fastbee.http.model.Location;
import com.fastbee.http.model.Result;
import com.fastbee.http.utils.Constants;
import com.fastbee.http.utils.MD5Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class HttpclientNode {
    @Resource
    private Amap amap;

    @Resource
    private Gitee gitee;

    @Resource
    private Cn12306 cn12306;

    @Resource
    private Yunchache yunchache;

    public Result<Location> amapLocation(BigDecimal longitude, BigDecimal latitude) {
        Result<Location> result = amap.getLocation(longitude.toEngineeringString(), latitude.toEngineeringString());
        return result;
    }

    public String gitee() {
        String result = gitee.index();
        return result;
    }

    public String cn12306() {
        ForestResponse<String> response = cn12306.index();
        return response.getResult();
    }

    public void yunchache() {
        Map<String, Object> base = Constants.getComParams();
        Map<String, Object> params = new HashMap<>();
        params.put("userId", Constants.userId);
        params.put("password", MD5Utils.getmd5("888"));
        ForestResponse<Map> response = yunchache.login(base,params);
        log.info("response.getResult: {}!",response.getResult());
    }

}
