module Multiwoven::Integrations::Destination::SalesforceConsumerGoodsCloud::SchemaHelper
def salesforce_field_to_json_schema_type(sf_field) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
def salesforce_field_to_json_schema_type(sf_field) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
case sf_field["type"]
when "string", "Email", "Phone", "Text", "TextArea", "TextEncrypted", "URL", "Picklist (Single)"
if sf_field["nillable"]
{ "type": %w[string null] }
else
{ "type": "string" }
end
when "double", "Currency", "Percent"
if sf_field["nillable"]
{ "type": %w[number null] }
else
{ "type": "number" }
end
when "boolean", "Checkbox"
if sf_field["nillable"]
{ "type": %w[boolean null] }
else
{ "type": "boolean" }
end
when "int", "AutoNumber"
if sf_field["nillable"]
{ "type": %w[integer null] }
else
{ "type": "integer" }
end
when "date"
if sf_field["nillable"]
{ "type": %w[string null], "format": "date" }
else
{ "type": "string", "format": "date" }
end
when "datetime", "DateTime"
if sf_field["nillable"]
{ "type": %w[string null], "format": "date-time" }
else
{ "type": "string", "format": "date-time" }
end
when "time"
if sf_field["nillable"]
{ "type": %w[string null], "format": "time" }
else
{ "type": "string", "format": "time" }
end
when "textarea", "Text Area (Long)", "Text Area (Rich)"
if sf_field["nillable"]
{ "type": %w[string null] }
else
{ "type": "string" }
end
when "picklist", "multipicklist", "Picklist (Multi-select)"
if sf_field[:picklistValues] && sf_field["nillable"]
enum_values = sf_field[:picklistValues].map { |val| val["value"] }
{ "type": %w[string null], "items": { "type": "string" }, "enum": enum_values }
elsif sf_field[:picklistValues]
enum_values = sf_field[:picklistValues].map { |val| val["value"] }
{ "type": "string", "items": { "type": "string" }, "enum": enum_values }
else
{ "type": "string", "items": { "type": "string" } }
end
when "reference", "Reference (Lookup & Master-Detail)"
if sf_field["nillable"]
{ "type": %w[string null] }
else
{ "type": "string" }
end
when "location", "Geolocation"
if sf_field["nillable"]
{ "type": %w[object null], "properties": { "latitude": { "type": "number" }, "longitude": { "type": "number" } } }
else
{ "type": "object", "properties": { "latitude": { "type": "number" }, "longitude": { "type": "number" } } }
end
else
if sf_field["nillable"]
{ "type": %w[string null] }
else
{ "type": "string" }
end
end
end