namespace ti_common {

    class CloudAgentAPI implements IAgentAPI {
        static $inject = ['$http'];

        constructor(private $http: angular.IHttpService) {

        };

        getLpListJson(): angular.IPromise<any> {
            return this.$http.get('target_setup/data/lpList.json');
        }

        getConfigInfo(OS: string): angular.IPromise<any> {
            return this.$http.get('/ticloudagent/getConfigInfo?os=' + OS);
        }

        getConfigurables(OS: string, connectionID: string, deviceID: string): angular.IPromise<string> {
            return this.$http.get('/ticloudagent/getConfigurables/' + OS + '/' + connectionID + '/' + deviceID);
        }

        getSupportingFiles(ccxmlFileContents: string, OS: string, osBits?: number): angular.IPromise<any> {
            let path = '/ticloudagent/getSupportingFiles?';
            path += 'os=' + OS;
            if (osBits) {
                path += '&bitSize=' + osBits;
            }

            return this.$http.post(path, ccxmlFileContents, {
                headers: {
                    'Content-Type': 'application/xml'
                }
            });
        }

        queryConfig(ccxmlFileContents: string, OS: string): angular.IPromise<any> {
            return this.$http.post('/ticloudagent/queryConfig?os=' + OS, ccxmlFileContents, {
                headers: {
                    'Content-Type': 'application/xml'
                }
            });
        }

        getConfig(OS: string, connectionID: string, deviceID: string, configurablesJson?: string): angular.IPromise<string> {

            if (configurablesJson) {
                return this.$http.post('/ticloudagent/getConfigAdvanced?os=' + OS
                    + '&connectionID=' + connectionID
                    + '&deviceID=' + deviceID,
                    configurablesJson
                    , {
                        headers: {
                            'Content-Type': 'application/text'
                        }
                    });
               
            }
            else {
                return this.$http.get('/ticloudagent/getConfig/' + OS + '/' + connectionID + '/' + deviceID);
            }

        }

        getFileContent(OS: string, path: string, contentType?: ti_common.file.ContentType, version?: string): angular.IPromise<string> {
            if (!contentType) {
                contentType = ti_common.file.ContentType.Text;
            }

            if (!version) {
                version = "LATEST";
            }

            return this.$http.get('/ticloudagent/getFile/' + OS + "/" + path + "/" + version, { responseType: ti_common.file.ResponseTypeConfigLookup[contentType] });
        }
		
		// stub implementation for cloud, as we don't have a need to shutdown dinfra at this time
		closeAgent(): angular.IPromise<any> {
			return;
		}
    };

    angular.module('ti_common').service('ticAgentAPI', CloudAgentAPI);
}