{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:gluendo:schema:crm:customer:v1.0.0",
  "title": "Customer",
  "description": "Canonical representation of a customer entity. Produced by CRM systems (e.g., Salesforce, HubSpot, custom CRM) on customer lifecycle events (created, updated, churned).",
  "type": "object",
  "required": [
    "customerId"
  ],
  "properties": {
    "customerId": {
      "type": "string",
      "description": "Unique customer identifier"
    },
    "companyName": {
      "type": "string",
      "description": "Legal company or organization name"
    },
    "tradingName": {
      "type": "string",
      "description": "Trading or brand name, if different from legal name"
    },
    "status": {
      "oneOf": [
        {
          "const": "prospect",
          "description": "Potential customer, not yet converted"
        },
        {
          "const": "active",
          "description": "Active paying customer"
        },
        {
          "const": "inactive",
          "description": "Customer with no recent activity"
        },
        {
          "const": "churned",
          "description": "Former customer who has left"
        }
      ],
      "description": "Current customer lifecycle status"
    },
    "industry": {
      "type": "string",
      "description": "Industry or sector the customer operates in"
    },
    "website": {
      "type": "string",
      "format": "uri",
      "description": "Customer website URL"
    },
    "primaryContact": {
      "title": "Contact Information",
      "description": "Primary contact person",
      "type": "object",
      "properties": {
        "email": {
          "type": "string",
          "format": "email",
          "description": "Primary email address"
        },
        "phoneNumber": {
          "type": "string",
          "description": "Phone number in E.164 format (e.g., +33612345678)",
          "pattern": "^\\+[1-9]\\d{1,14}$"
        }
      }
    },
    "billingAddress": {
      "title": "Address",
      "description": "Billing address",
      "type": "object",
      "required": [
        "country"
      ],
      "properties": {
        "streetAddress": {
          "type": "string",
          "description": "Street name, number, and any additional line (apt, suite, etc.)"
        },
        "city": {
          "type": "string",
          "description": "City or locality name"
        },
        "stateOrProvince": {
          "type": "string",
          "description": "State, province, region, or equivalent administrative division"
        },
        "postalCode": {
          "type": "string",
          "description": "Postal or ZIP code"
        },
        "country": {
          "title": "Country Code Alpha-2",
          "description": "ISO 3166-1 alpha-2 country code",
          "type": "string",
          "enum": [
            "AD",
            "AE",
            "AF",
            "AG",
            "AI",
            "AL",
            "AM",
            "AO",
            "AQ",
            "AR",
            "AS",
            "AT",
            "AU",
            "AW",
            "AX",
            "AZ",
            "BA",
            "BB",
            "BD",
            "BE",
            "BF",
            "BG",
            "BH",
            "BI",
            "BJ",
            "BL",
            "BM",
            "BN",
            "BO",
            "BQ",
            "BR",
            "BS",
            "BT",
            "BV",
            "BW",
            "BY",
            "BZ",
            "CA",
            "CC",
            "CD",
            "CF",
            "CG",
            "CH",
            "CI",
            "CK",
            "CL",
            "CM",
            "CN",
            "CO",
            "CR",
            "CU",
            "CV",
            "CW",
            "CX",
            "CY",
            "CZ",
            "DE",
            "DJ",
            "DK",
            "DM",
            "DO",
            "DZ",
            "EC",
            "EE",
            "EG",
            "EH",
            "ER",
            "ES",
            "ET",
            "FI",
            "FJ",
            "FK",
            "FM",
            "FO",
            "FR",
            "GA",
            "GB",
            "GD",
            "GE",
            "GF",
            "GG",
            "GH",
            "GI",
            "GL",
            "GM",
            "GN",
            "GP",
            "GQ",
            "GR",
            "GS",
            "GT",
            "GU",
            "GW",
            "GY",
            "HK",
            "HM",
            "HN",
            "HR",
            "HT",
            "HU",
            "ID",
            "IE",
            "IL",
            "IM",
            "IN",
            "IO",
            "IQ",
            "IR",
            "IS",
            "IT",
            "JE",
            "JM",
            "JO",
            "JP",
            "KE",
            "KG",
            "KH",
            "KI",
            "KM",
            "KN",
            "KP",
            "KR",
            "KW",
            "KY",
            "KZ",
            "LA",
            "LB",
            "LC",
            "LI",
            "LK",
            "LR",
            "LS",
            "LT",
            "LU",
            "LV",
            "LY",
            "MA",
            "MC",
            "MD",
            "ME",
            "MF",
            "MG",
            "MH",
            "MK",
            "ML",
            "MM",
            "MN",
            "MO",
            "MP",
            "MQ",
            "MR",
            "MS",
            "MT",
            "MU",
            "MV",
            "MW",
            "MX",
            "MY",
            "MZ",
            "NA",
            "NC",
            "NE",
            "NF",
            "NG",
            "NI",
            "NL",
            "NO",
            "NP",
            "NR",
            "NU",
            "NZ",
            "OM",
            "PA",
            "PE",
            "PF",
            "PG",
            "PH",
            "PK",
            "PL",
            "PM",
            "PN",
            "PR",
            "PS",
            "PT",
            "PW",
            "PY",
            "QA",
            "RE",
            "RO",
            "RS",
            "RU",
            "RW",
            "SA",
            "SB",
            "SC",
            "SD",
            "SE",
            "SG",
            "SH",
            "SI",
            "SJ",
            "SK",
            "SL",
            "SM",
            "SN",
            "SO",
            "SR",
            "SS",
            "ST",
            "SV",
            "SX",
            "SY",
            "SZ",
            "TC",
            "TD",
            "TF",
            "TG",
            "TH",
            "TJ",
            "TK",
            "TL",
            "TM",
            "TN",
            "TO",
            "TR",
            "TT",
            "TV",
            "TW",
            "TZ",
            "UA",
            "UG",
            "UM",
            "US",
            "UY",
            "UZ",
            "VA",
            "VC",
            "VE",
            "VG",
            "VI",
            "VN",
            "VU",
            "WF",
            "WS",
            "YE",
            "YT",
            "ZA",
            "ZM",
            "ZW"
          ],
          "examples": [
            "FR",
            "US"
          ]
        }
      }
    },
    "shippingAddress": {
      "title": "Address",
      "description": "Shipping address, if different from billing",
      "type": "object",
      "required": [
        "country"
      ],
      "properties": {
        "streetAddress": {
          "type": "string",
          "description": "Street name, number, and any additional line (apt, suite, etc.)"
        },
        "city": {
          "type": "string",
          "description": "City or locality name"
        },
        "stateOrProvince": {
          "type": "string",
          "description": "State, province, region, or equivalent administrative division"
        },
        "postalCode": {
          "type": "string",
          "description": "Postal or ZIP code"
        },
        "country": {
          "title": "Country Code Alpha-2",
          "description": "ISO 3166-1 alpha-2 country code",
          "type": "string",
          "enum": [
            "AD",
            "AE",
            "AF",
            "AG",
            "AI",
            "AL",
            "AM",
            "AO",
            "AQ",
            "AR",
            "AS",
            "AT",
            "AU",
            "AW",
            "AX",
            "AZ",
            "BA",
            "BB",
            "BD",
            "BE",
            "BF",
            "BG",
            "BH",
            "BI",
            "BJ",
            "BL",
            "BM",
            "BN",
            "BO",
            "BQ",
            "BR",
            "BS",
            "BT",
            "BV",
            "BW",
            "BY",
            "BZ",
            "CA",
            "CC",
            "CD",
            "CF",
            "CG",
            "CH",
            "CI",
            "CK",
            "CL",
            "CM",
            "CN",
            "CO",
            "CR",
            "CU",
            "CV",
            "CW",
            "CX",
            "CY",
            "CZ",
            "DE",
            "DJ",
            "DK",
            "DM",
            "DO",
            "DZ",
            "EC",
            "EE",
            "EG",
            "EH",
            "ER",
            "ES",
            "ET",
            "FI",
            "FJ",
            "FK",
            "FM",
            "FO",
            "FR",
            "GA",
            "GB",
            "GD",
            "GE",
            "GF",
            "GG",
            "GH",
            "GI",
            "GL",
            "GM",
            "GN",
            "GP",
            "GQ",
            "GR",
            "GS",
            "GT",
            "GU",
            "GW",
            "GY",
            "HK",
            "HM",
            "HN",
            "HR",
            "HT",
            "HU",
            "ID",
            "IE",
            "IL",
            "IM",
            "IN",
            "IO",
            "IQ",
            "IR",
            "IS",
            "IT",
            "JE",
            "JM",
            "JO",
            "JP",
            "KE",
            "KG",
            "KH",
            "KI",
            "KM",
            "KN",
            "KP",
            "KR",
            "KW",
            "KY",
            "KZ",
            "LA",
            "LB",
            "LC",
            "LI",
            "LK",
            "LR",
            "LS",
            "LT",
            "LU",
            "LV",
            "LY",
            "MA",
            "MC",
            "MD",
            "ME",
            "MF",
            "MG",
            "MH",
            "MK",
            "ML",
            "MM",
            "MN",
            "MO",
            "MP",
            "MQ",
            "MR",
            "MS",
            "MT",
            "MU",
            "MV",
            "MW",
            "MX",
            "MY",
            "MZ",
            "NA",
            "NC",
            "NE",
            "NF",
            "NG",
            "NI",
            "NL",
            "NO",
            "NP",
            "NR",
            "NU",
            "NZ",
            "OM",
            "PA",
            "PE",
            "PF",
            "PG",
            "PH",
            "PK",
            "PL",
            "PM",
            "PN",
            "PR",
            "PS",
            "PT",
            "PW",
            "PY",
            "QA",
            "RE",
            "RO",
            "RS",
            "RU",
            "RW",
            "SA",
            "SB",
            "SC",
            "SD",
            "SE",
            "SG",
            "SH",
            "SI",
            "SJ",
            "SK",
            "SL",
            "SM",
            "SN",
            "SO",
            "SR",
            "SS",
            "ST",
            "SV",
            "SX",
            "SY",
            "SZ",
            "TC",
            "TD",
            "TF",
            "TG",
            "TH",
            "TJ",
            "TK",
            "TL",
            "TM",
            "TN",
            "TO",
            "TR",
            "TT",
            "TV",
            "TW",
            "TZ",
            "UA",
            "UG",
            "UM",
            "US",
            "UY",
            "UZ",
            "VA",
            "VC",
            "VE",
            "VG",
            "VI",
            "VN",
            "VU",
            "WF",
            "WS",
            "YE",
            "YT",
            "ZA",
            "ZM",
            "ZW"
          ],
          "examples": [
            "FR",
            "US"
          ]
        }
      }
    },
    "taxId": {
      "type": "string",
      "description": "Tax identification number (VAT, EIN, etc.)"
    },
    "accountManagerId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Identifier of the assigned account manager"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "Timestamp when the customer record was created (ISO 8601)"
    },
    "tags": {
      "title": "Tags",
      "description": "Metadata tags for segmentation and filtering",
      "type": "array",
      "maxItems": 50,
      "items": {
        "type": "object",
        "required": [
          "key",
          "value"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Tag key: alphanumeric, hyphens, and underscores allowed",
            "pattern": "^[a-zA-Z0-9_-]{1,64}$",
            "maxLength": 64
          },
          "value": {
            "type": "string",
            "description": "Tag value",
            "maxLength": 256
          }
        }
      },
      "examples": [
        [
          {
            "key": "env",
            "value": "production"
          },
          {
            "key": "cost-center",
            "value": "engineering-platform"
          }
        ]
      ]
    }
  }
}
