global class IpscapeHelper {
    webService static String getCapabilities() {
        Map<String, String> Capabilities = new Map<String, String>{'getLead' => 'IpscapeHelper::getLead', 'getOpportunity' => 'IpscapeHelper::getOpportunity', 'getTask' => 'IpscapeHelper::getTask'};
        return JSON.serialize(Capabilities);
    }

    webService static String getLead(String leadId) {
      List<Lead> leads = Database.query('Select Id, Name, phone, IsConverted, ConvertedOpportunityId, ConvertedAccountId, ConvertedContactId from Lead where Id = :leadId limit 1');
      if (leads.size() > 0) {
        return JSON.serialize(leads[0]);
      }
      return JSON.serialize(null);
    }

    webService static String getOpportunity(String opportunityId) {
      List<Opportunity> opportunities = Database.query('Select Id, Name, Type, AccountId from Opportunity where Id = :opportunityId limit 1');
      if (opportunities.size() > 0) {
        return JSON.serialize(opportunities[0]);
      }
      return JSON.serialize(null);
    }

    webService static String getTask(String interactionId) {
      List<Task> tasks = Database.query('Select Id, CallObject, ActivityDate, CallType, Subject, Description, WhatId, WhoId from Task where CallObject = :interactionId limit 1');
      if (tasks.size() > 0) {
        return JSON.serialize(tasks[0]);
      }
      return JSON.serialize(null);
    }
}
