// Path: src/main/java/com/integrationagent/hubspotApi/domain/HSContact.java
// public class HSContact {
// 
//     private Map<String, String> properties = new HashMap<>();
// 
//     public HSContact() {
//     }
// 
//     public HSContact(String email, String firstname, String lastname) {
//         this.properties.put("email", email);
//         this.properties.put("firstname", firstname);
//         this.properties.put("lastname", lastname);
//     }
// 
//     public HSContact(long id, String email, String firstname, String lastname, Map<String, String> properties) {
//         this.properties.put("vid", Long.toString(id));
//         this.properties.put("email", email);
//         this.properties.put("firstname", firstname);
//         this.properties.put("lastname", lastname);
//         this.properties.putAll(properties);
//     }
// 
//     public long getId() {
//         return !Strings.isNullOrEmpty(this.properties.get("vid")) ? Long.parseLong(this.properties.get("vid")) : 0;
//     }
// 
//     public HSContact setId(long id) {
//         this.properties.put("vid", Long.toString(id));
//         return this;
//     }
// 
//     public String getEmail() {
//         return this.properties.get("email");
//     }
// 
//     public HSContact setEmail(String email) {
//         this.properties.put("email", email);
//         return this;
//     }
// 
//     public String getFirstname() {
//         return this.properties.get("firstname");
//     }
// 
//     public HSContact setFirstname(String firstname) {
//         this.properties.put("firstname", firstname);
//         return this;
//     }
// 
//     public String getLastname() {
//         return this.properties.get("lastname");
//     }
// 
//     public HSContact setLastname(String lastname) {
//         this.properties.put("lastname", lastname);
//         return this;
//     }
// 
//     public Map<String, String> getProperties() {
//         return properties;
//     }
// 
//     public HSContact addProperties(Map<String, String> properties) {
//         properties.forEach((k, v) -> this.setProperty(k, v));
//         return this;
//     }
// 
//     public HSContact setProperties(Map<String, String> properties) {
//         this.properties = properties;
//         return this;
//     }
// 
//     public HSContact setProperty(String property, String value) {
//         if(value != null && !value.equals("null")){
//             this.properties.put(property, value);
//         }
// 
//         return this;
//     }
// 
//     public String getProperty(String property) {
//         return this.properties.get(property);
//     }
// 
//     public String toJsonString() {
//         return toJson().toString();
//     }
// 
//     public JSONObject toJson() {
// 
//         Map<String, String> properties = new HashMap<>(getProperties());
//         properties.remove("vid");
// 
//         return HubSpotHelper.mapToJson(properties);
//     }
// }
// 
// Path: src/main/java/com/integrationagent/hubspotApi/utils/HubSpotException.java
// public class HubSpotException extends Exception {
// 
// 	private int code;
// 
// 	private String rawMessage;
// 
// 	public HubSpotException(String message) {
// 		super(message);
// 	}
// 
// 	public HubSpotException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public HubSpotException(String message, int code) {
// 		super(message);
// 		this.code = code;
// 	}
// 
// 	public HubSpotException(String message, String rawMessage) {
// 		super(message);
// 		this.rawMessage = rawMessage;
// 	}
// 
// 	public int getCode() {
// 		return code;
// 	}
// 
// 	public String getRawMessage() {
// 		return rawMessage;
// 	}
// 
// 	public void setRawMessage(String rawMessage) {
// 		this.rawMessage = rawMessage;
// 	}
// }


import com.google.common.base.Strings;
import com.integrationagent.hubspotApi.domain.HSContact;
import com.integrationagent.hubspotApi.utils.HubSpotException;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
import java.util.Set;
package com.integrationagent.hubspotApi.service;



public class HSContactService {

    private HttpService httpService;

    public HSContactService(HttpService httpService) {
        this.httpService = httpService;
    }

    public HSContact getByEmail(String email) throws HubSpotException {
        String url = "/contacts/v1/contact/email/" + email + "/profile";
        return getContact(url);
    }

    public HSContact getByID(long id) throws HubSpotException{
        String url = "/contacts/v1/contact/vid/" + id + "/profile";
        return getContact(url);
    }

    private HSContact getContact(String url) throws HubSpotException {
        try {
            return parseContactData((JSONObject) httpService.getRequest(url));
        } catch (HubSpotException e) {
            if (e.getMessage().equals("Not Found")) {
                return null;
            } else {
                throw e;
            }
        }
    }

// Path: src/main/java/com/integrationagent/hubspotApi/domain/HSContact.java
// public class HSContact {
// 
//     private Map<String, String> properties = new HashMap<>();
// 
//     public HSContact() {
//     }
// 
//     public HSContact(String email, String firstname, String lastname) {
//         this.properties.put("email", email);
//         this.properties.put("firstname", firstname);
//         this.properties.put("lastname", lastname);
//     }
// 
//     public HSContact(long id, String email, String firstname, String lastname, Map<String, String> properties) {
//         this.properties.put("vid", Long.toString(id));
//         this.properties.put("email", email);
//         this.properties.put("firstname", firstname);
//         this.properties.put("lastname", lastname);
//         this.properties.putAll(properties);
//     }
// 
//     public long getId() {
//         return !Strings.isNullOrEmpty(this.properties.get("vid")) ? Long.parseLong(this.properties.get("vid")) : 0;
//     }
// 
//     public HSContact setId(long id) {
//         this.properties.put("vid", Long.toString(id));
//         return this;
//     }
// 
//     public String getEmail() {
//         return this.properties.get("email");
//     }
// 
//     public HSContact setEmail(String email) {
//         this.properties.put("email", email);
//         return this;
//     }
// 
//     public String getFirstname() {
//         return this.properties.get("firstname");
//     }
// 
//     public HSContact setFirstname(String firstname) {
//         this.properties.put("firstname", firstname);
//         return this;
//     }
// 
//     public String getLastname() {
//         return this.properties.get("lastname");
//     }
// 
//     public HSContact setLastname(String lastname) {
//         this.properties.put("lastname", lastname);
//         return this;
//     }
// 
//     public Map<String, String> getProperties() {
//         return properties;
//     }
// 
//     public HSContact addProperties(Map<String, String> properties) {
//         properties.forEach((k, v) -> this.setProperty(k, v));
//         return this;
//     }
// 
//     public HSContact setProperties(Map<String, String> properties) {
//         this.properties = properties;
//         return this;
//     }
// 
//     public HSContact setProperty(String property, String value) {
//         if(value != null && !value.equals("null")){
//             this.properties.put(property, value);
//         }
// 
//         return this;
//     }
// 
//     public String getProperty(String property) {
//         return this.properties.get(property);
//     }
// 
//     public String toJsonString() {
//         return toJson().toString();
//     }
// 
//     public JSONObject toJson() {
// 
//         Map<String, String> properties = new HashMap<>(getProperties());
//         properties.remove("vid");
// 
//         return HubSpotHelper.mapToJson(properties);
//     }
// }
// 
// Path: src/main/java/com/integrationagent/hubspotApi/utils/HubSpotException.java
// public class HubSpotException extends Exception {
// 
// 	private int code;
// 
// 	private String rawMessage;
// 
// 	public HubSpotException(String message) {
// 		super(message);
// 	}
// 
// 	public HubSpotException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public HubSpotException(String message, int code) {
// 		super(message);
// 		this.code = code;
// 	}
// 
// 	public HubSpotException(String message, String rawMessage) {
// 		super(message);
// 		this.rawMessage = rawMessage;
// 	}
// 
// 	public int getCode() {
// 		return code;
// 	}
// 
// 	public String getRawMessage() {
// 		return rawMessage;
// 	}
// 
// 	public void setRawMessage(String rawMessage) {
// 		this.rawMessage = rawMessage;
// 	}
// }


// Path: src/main/java/com/integrationagent/hubspotApi/service/HSContactService.java
import com.google.common.base.Strings;
import com.integrationagent.hubspotApi.domain.HSContact;
import com.integrationagent.hubspotApi.utils.HubSpotException;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
import java.util.Set;

package com.integrationagent.hubspotApi.service;



public class HSContactService {

    private HttpService httpService;

    public HSContactService(HttpService httpService) {
        this.httpService = httpService;
    }

    public HSContact getByEmail(String email) throws HubSpotException {
        String url = "/contacts/v1/contact/email/" + email + "/profile";
        return getContact(url);
    }

    public HSContact getByID(long id) throws HubSpotException{
        String url = "/contacts/v1/contact/vid/" + id + "/profile";
        return getContact(url);
    }

    private HSContact getContact(String url) throws HubSpotException {
        try {
            return parseContactData((JSONObject) httpService.getRequest(url));
        } catch (HubSpotException e) {
            if (e.getMessage().equals("Not Found")) {
                return null;
            } else {
                throw e;
            }
        }
    }

    public HSContact create(HSContact HSContact) throws HubSpotException {