{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-contact-schema.json",
  "title": "Contact",
  "x-generated": "2026-10-31",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-openapi.json#/components/schemas/Contact",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/ContactId"
    },
    "namespaceId": {
      "anyOf": [
        {
          "$ref": "#/$defs/NamespaceId"
        },
        {
          "type": "null"
        }
      ]
    },
    "name": {
      "type": "string"
    },
    "displayName": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "avatar": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "paused",
        "blocked",
        "archived"
      ]
    },
    "statusReason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "externalId": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "identities": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ContactIdentity"
      }
    },
    "profile": {
      "anyOf": [
        {
          "$ref": "#/$defs/ContactProfile"
        },
        {
          "type": "null"
        }
      ]
    },
    "preferences": {
      "anyOf": [
        {
          "$ref": "#/$defs/ContactPreferences"
        },
        {
          "type": "null"
        }
      ]
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "metadata": {
      "anyOf": [
        {
          "$ref": "#/$defs/JsonObject"
        },
        {
          "type": "null"
        }
      ]
    },
    "importProvenance": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "first": {
              "type": "object",
              "properties": {
                "jobId": {
                  "$ref": "#/$defs/ContactImportJobId"
                },
                "topicId": {
                  "$ref": "#/$defs/TopicId"
                },
                "preset": {
                  "type": "string",
                  "enum": [
                    "beehiiv",
                    "substack",
                    "kit",
                    "mailchimp"
                  ]
                },
                "importedAt": {
                  "type": "string"
                },
                "summary": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "signupAt": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "value": {
                                  "type": "string",
                                  "maxLength": 160,
                                  "x-samva-string-checks": [
                                    {
                                      "id": "effect/schema/isMaxLength",
                                      "payload": {
                                        "maxLength": 160
                                      }
                                    }
                                  ]
                                },
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "time",
                                    "text"
                                  ]
                                }
                              },
                              "required": [
                                "value",
                                "kind"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "sources": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 160,
                            "x-samva-string-checks": [
                              {
                                "id": "effect/schema/isMaxLength",
                                "payload": {
                                  "maxLength": 160
                                }
                              }
                            ]
                          },
                          "maxItems": 8
                        },
                        "omittedSources": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        }
                      },
                      "required": [
                        "signupAt",
                        "sources",
                        "omittedSources"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "evidence": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "file": {
                        "type": "string"
                      },
                      "row": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "declared": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "status_column"
                                ]
                              }
                            },
                            "required": [
                              "kind"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "export_scope"
                                ]
                              },
                              "scope": {
                                "type": "string",
                                "enum": [
                                  "subscribed",
                                  "unsubscribed",
                                  "suppressed",
                                  "cleaned/bounced"
                                ]
                              }
                            },
                            "required": [
                              "kind",
                              "scope"
                            ],
                            "additionalProperties": false
                          }
                        ]
                      },
                      "suppressionFree": {
                        "type": "boolean"
                      },
                      "sourceStatus": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "signupAt": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "source": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    },
                    "required": [
                      "file",
                      "row",
                      "declared",
                      "suppressionFree",
                      "sourceStatus",
                      "signupAt",
                      "source"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "required": [
                "jobId",
                "topicId",
                "preset",
                "importedAt",
                "evidence"
              ],
              "additionalProperties": false
            },
            "latest": {
              "type": "object",
              "properties": {
                "jobId": {
                  "$ref": "#/$defs/ContactImportJobId"
                },
                "topicId": {
                  "$ref": "#/$defs/TopicId"
                },
                "preset": {
                  "type": "string",
                  "enum": [
                    "beehiiv",
                    "substack",
                    "kit",
                    "mailchimp"
                  ]
                },
                "importedAt": {
                  "type": "string"
                },
                "summary": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "signupAt": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "value": {
                                  "type": "string",
                                  "maxLength": 160,
                                  "x-samva-string-checks": [
                                    {
                                      "id": "effect/schema/isMaxLength",
                                      "payload": {
                                        "maxLength": 160
                                      }
                                    }
                                  ]
                                },
                                "kind": {
                                  "type": "string",
                                  "enum": [
                                    "time",
                                    "text"
                                  ]
                                }
                              },
                              "required": [
                                "value",
                                "kind"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "sources": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "maxLength": 160,
                            "x-samva-string-checks": [
                              {
                                "id": "effect/schema/isMaxLength",
                                "payload": {
                                  "maxLength": 160
                                }
                              }
                            ]
                          },
                          "maxItems": 8
                        },
                        "omittedSources": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        }
                      },
                      "required": [
                        "signupAt",
                        "sources",
                        "omittedSources"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "evidence": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "file": {
                        "type": "string"
                      },
                      "row": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "declared": {
                        "anyOf": [
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "status_column"
                                ]
                              }
                            },
                            "required": [
                              "kind"
                            ],
                            "additionalProperties": false
                          },
                          {
                            "type": "object",
                            "properties": {
                              "kind": {
                                "type": "string",
                                "enum": [
                                  "export_scope"
                                ]
                              },
                              "scope": {
                                "type": "string",
                                "enum": [
                                  "subscribed",
                                  "unsubscribed",
                                  "suppressed",
                                  "cleaned/bounced"
                                ]
                              }
                            },
                            "required": [
                              "kind",
                              "scope"
                            ],
                            "additionalProperties": false
                          }
                        ]
                      },
                      "suppressionFree": {
                        "type": "boolean"
                      },
                      "sourceStatus": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "signupAt": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "source": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    },
                    "required": [
                      "file",
                      "row",
                      "declared",
                      "suppressionFree",
                      "sourceStatus",
                      "signupAt",
                      "source"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "required": [
                "jobId",
                "topicId",
                "preset",
                "importedAt",
                "evidence"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "first",
            "latest"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "namespaceId",
    "name",
    "displayName",
    "avatar",
    "status",
    "statusReason",
    "externalId",
    "identities",
    "profile",
    "preferences",
    "tags",
    "metadata",
    "importProvenance",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false,
  "$defs": {
    "ContactConsent": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "opted_in",
            "opted_out"
          ]
        },
        "source": {
          "type": "string"
        },
        "capturedAt": {
          "type": "string"
        },
        "proof": {
          "anyOf": [
            {
              "$ref": "#/$defs/JsonObject"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "status",
        "source",
        "capturedAt",
        "proof"
      ],
      "additionalProperties": false
    },
    "ContactCustomFields": {
      "type": "object",
      "additionalProperties": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "number"
          },
          {
            "type": "boolean"
          },
          {
            "type": "null"
          }
        ]
      }
    },
    "ContactId": {
      "type": "string",
      "pattern": "^contact_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactId"
    },
    "ContactIdentity": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/ContactIdentityId"
        },
        "type": {
          "type": "string",
          "enum": [
            "email",
            "phone"
          ]
        },
        "identifier": {
          "type": "string"
        },
        "verified": {
          "type": "boolean"
        },
        "channels": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ContactIdentityChannel"
          }
        }
      },
      "required": [
        "id",
        "type",
        "identifier",
        "verified",
        "channels"
      ],
      "additionalProperties": false
    },
    "ContactIdentityChannel": {
      "type": "object",
      "properties": {
        "channel": {
          "type": "string",
          "enum": [
            "email"
          ]
        },
        "reachability": {
          "type": "string",
          "enum": [
            "unknown",
            "reachable",
            "unreachable"
          ]
        },
        "consent": {
          "anyOf": [
            {
              "$ref": "#/$defs/ContactConsent"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "channel",
        "reachability",
        "consent"
      ],
      "additionalProperties": false
    },
    "ContactIdentityId": {
      "type": "string",
      "pattern": "^cident_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactIdentityId"
    },
    "ContactImportJobId": {
      "type": "string",
      "pattern": "^cimport_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactImportJobId"
    },
    "ContactLocation": {
      "type": "object",
      "properties": {
        "country": {
          "type": "string"
        },
        "state": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "timezone": {
          "type": "string"
        }
      },
      "required": [
        "country",
        "state",
        "city",
        "timezone"
      ],
      "additionalProperties": false
    },
    "ContactPreferences": {
      "type": "object",
      "properties": {
        "preferredChannels": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "email"
                ]
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "language": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "timezone": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "notifications": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "email": {
                  "anyOf": [
                    {
                      "type": "boolean"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "quiet_hours": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "start": {
                          "type": "string"
                        },
                        "end": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "start",
                        "end"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "ContactProfile": {
      "type": "object",
      "properties": {
        "firstName": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastName": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "company": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "jobTitle": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "location": {
          "anyOf": [
            {
              "$ref": "#/$defs/ContactLocation"
            },
            {
              "type": "null"
            }
          ]
        },
        "customFields": {
          "anyOf": [
            {
              "$ref": "#/$defs/ContactCustomFields"
            },
            {
              "type": "null"
            }
          ]
        },
        "source": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "api",
                "import",
                "manual",
                "form"
              ]
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "JsonObject": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/JsonValue"
      }
    },
    "JsonValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    },
    "NamespaceId": {
      "type": "string",
      "pattern": "^ns_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "NamespaceId"
    },
    "TopicId": {
      "type": "string",
      "pattern": "^unsub_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TopicId"
    }
  }
}