{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://www.salesteamportal.com/addDirectMarketingInteraction",
    "title": "addDirectMarketingInteraction",
    "description": "payload for addDirectMarketingInteraction operation",

    "anyOf" : [

        {
            "type" : "array",
            "items" : { "$ref" : "#/$defs/directMarketingInteraction" },
            "minItems" : 1,
            "maxItems" : 100
        },
        {
            "$ref" : "#/$defs/directMarketingInteraction"
        }
    ],

    "$defs" : {
        "directMarketingInteraction" : {
            "type": "object",
            "properties" : {

                "company_type" : { "type" : "string", "const" : "OPERATOR", "default" : "OPERATOR" },

                "company_id" : {
                    "type" : "integer"
                },
                "company_address" : {
                    "type" : "string",
                    "maxLength" : 150
                },
                "company_city" : {
                    "type" : "string",
                    "maxLength" : 75
                },
                "company_name" : {
                    "type" : "string",
                    "maxLength" : 150
                },
                "company_phone" : {
                    "type" : "string",
                    "maxLength" : 30
                },
                "company_state" : {
                    "type" : "string",
                    "maxLength" : 25
                },
                "company_zip" : {
                    "type" : "string",
                    "maxLength" : 10
                },

                "contact_id" : {
                    "type" : "integer"
                },
                "contact_email" : {
                    "type" : "string",
                    "maxLength" : 150,
                    "pattern" : "^[\\d\\w._-]+@[\\d\\w._-]+\\.[\\w]+$"
                },
                "contact_first_name" : {
                    "type" : "string",
                    "maxLength" : 75
                },
                "contact_last_name" : {
                    "type" : "string",
                    "maxLength" : 75
                },
                "contact_phone" : {
                    "type" : "string",
                    "maxLength" : 30
                },
                "contact_title" : {
                    "type" : "string",
                    "maxLength" : 75
                },

                "salesperson_email" : {
                    "type" : "string",
                    "maxLength" : 150,
                    "pattern" : "^[\\d\\w._-]+@[\\d\\w._-]+\\.[\\w]+$"
                },
                "salesperson_first_name" : {
                    "type" : "string"
                },
                "salesperson_last_name" : {
                    "type" : "string"
                },

                "email_name" : {
                    "type" : "string",
                    "maxLength" : 100
                },

                "email_date" : {
                    "type" : "string",
                    "format" : "date",
                    "maxLength" : 10
                },

                "email_subject" : {
                    "type" : "string",
                    "maxLength" : 250
                },

                "email_reference_url" : {
                    "type" : "string",
                    "maxLength" : 2048
                },

                "email_content" : {
                    "type" : "string",
                    "maxLength" : 8000
                },

                "manufacturer_id" : { 
                    "type" : "integer"
                },

                "manufacturer_name" : { 
                    "type" : "string"
                }


            },
            "additionalProperties": false,
            "required" : [ "email_date", "email_name", "email_content", "contact_email", "salesperson_email" ],
            "allOf" : [
                {
                    "title" : "company_id required or company_name, company_address, company_city, company_state and company_zip required",
                    "anyOf" : [
                        { "required" : [ "company_id" ] },
                        { "required" : [ "company_name", "company_address", "company_city", "company_state", "company_zip" ]}
                    ]    
                },
                {
                    "title" : "manufacturer_id or manufacturer_name is required",
                    "anyOf" : [
                        { "required" : [ "manufacturer_id" ] },
                        { "required" : [ "manufacturer_name" ]}
                    ]    
                }
            ]
        }
    }
}