import { Common } from 'pc-component-v3';

/**
 * 工具类自动生成的API，请勿做任何修改，请勿做任何修改，请勿做任何修改（重要的事情说3遍）
 * 工具作者: 杨志杰
 *  
 */
export default {

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 创建模型 
	 */
  create: function(){
    var requestUrl = 'api/modelResource/create';


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'get',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据文件名创建模型 
	 */
  createModelByFile: function(files){
    var requestUrl = 'api/modelResource/createModelByFile';
    var paramCount = 0;
    if(files != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('files=' + files);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'post',
        contentType: false,
        processData: false,
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 删除Model 
	 */
  delete: function(modelId){
    var requestUrl = 'api/modelResource/delete/{modelId}';
    if(modelId != null){
      requestUrl = requestUrl.replace('{modelId}', modelId);
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'post',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 删除Model 
	 */
  deleteModels: function(modelIds){
    var requestUrl = 'api/modelResource/deleteModels';


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'post',
        contentType: 'application/json',
				
				
        data: JSON.stringify(modelIds),
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据Model部署流程 
	 */
  deploy: function(modelId){
    var requestUrl = 'api/modelResource/deploy/{modelId}';
    if(modelId != null){
      requestUrl = requestUrl.replace('{modelId}', modelId);
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'post',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 导出model的xml文件 
	 */
  export: function(modelId){
    var requestUrl = 'api/modelResource/export/{modelId}';
    if(modelId != null){
      requestUrl = requestUrl.replace('{modelId}', modelId);
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'get',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 *  
	 */
  getEditorJson: function(modelId){
    var requestUrl = 'api/modelResource/model/{modelId}/json';
    if(modelId != null){
      requestUrl = requestUrl.replace('{modelId}', modelId);
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'get',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 *  
	 */
  getStencilset: function(){
    var requestUrl = 'api/modelResource/editor/stencilset';


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'get',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 *  
	 */
  listModel: function(firstResult, maxResults, modelName, deploymentId){
    var requestUrl = 'api/modelResource/listModel';
    var paramCount = 0;
    if(firstResult != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('firstResult=' + firstResult);
      paramCount ++;
    }
    if(maxResults != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('maxResults=' + maxResults);
      paramCount ++;
    }
    if(modelName != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('modelName=' + modelName);
      paramCount ++;
    }
    if(deploymentId != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('deploymentId=' + deploymentId);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'get',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 *  
	 */
  saveModel: function(modelId, name, json_xml, svg_xml, description){
    var requestUrl = 'api/modelResource/model/{modelId}/save';
    if(modelId != null){
      requestUrl = requestUrl.replace('{modelId}', modelId);
    }
    var paramCount = 0;
    if(name != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('name=' + name);
      paramCount ++;
    }
    if(json_xml != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('json_xml=' + json_xml);
      paramCount ++;
    }
    if(svg_xml != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('svg_xml=' + svg_xml);
      paramCount ++;
    }
    if(description != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('description=' + description);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'post',
        contentType: 'application/x-www-form-urlencoded',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据Model部署流程 
	 */
  undeploy: function(modelId){
    var requestUrl = 'api/modelResource/undeploy/{modelId}';
    if(modelId != null){
      requestUrl = requestUrl.replace('{modelId}', modelId);
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiUrl2(requestUrl),
        type: 'post',
        contentType: 'application/json',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },
};
