import axios, { AxiosResponse } from 'axios';
import { Singleton } from "typescript-ioc";
import { MeClientRequestType } from './MeClientRequestType';

/**
 * 中台1.0通用客户端
 * @date 2021-05-08 17:14:32
 * @author 周勇强
 */
@Singleton
class MeClient {
    /**
     * 
     * @param parameters
     */
    async exec(msId: string, uri: string, version: string, requestType: MeClientRequestType, requestData?: {}): Promise<AxiosResponse> {
        let sid = `${msId}.${uri}`
        let config = {
            headers: {
                'sid': sid,
                'version': version
            },
            timeout: 30000,
            data: requestData
        };

        switch (requestType) {
            case MeClientRequestType.GET:
                console.log('执行GET...,config:%s', JSON.stringify(config))
                return await axios.get('https://mms-test.keytop.cn/', config);
            case MeClientRequestType.POST:
                console.log('执行post...,config:%s', JSON.stringify(config))
                return await axios.post('https://mms-test.keytop.cn/', {}, config);
        }
    }
}

export { MeClient }