openapi: "3.0.3"
info:
  title: "CRM customers API"
  version: "1.0.0"
  description: "A contact belongs to exactly one account, so accounts must be inserted before contacts. The marketing_opt_in column is a 0/1 integer rather than a boolean because the legacy CRM export stores it that way. Country is constrained to two letters, which is the constraint that catches synthetic data with full country names in it. Addresses reference contacts, so a contact with no address breaks the shipping preferences panel."
paths: {}
x-domain-id: "crm_customers"
x-dialect: "postgres"
components:
  schemas:
    accounts:
      type: "object"
      x-primary-key: "id"
      required: ["id", "name", "plan", "created_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        name:
          type: "string"
        plan:
          type: "string"
          enum: ["free", "team", "business"]
        created_at:
          type: "string"
          format: "date-time"
    contacts:
      type: "object"
      x-primary-key: "id"
      required: ["id", "account_id", "email", "full_name", "marketing_opt_in"]
      properties:
        id:
          type: "string"
          format: "uuid"
        account_id:
          $ref: "#/components/schemas/accounts"
        email:
          type: "string"
          format: "email"
          x-unique: true
        full_name:
          type: "string"
        marketing_opt_in:
          type: "integer"
          minimum: 0
          maximum: 1
    addresses:
      type: "object"
      x-primary-key: "id"
      required: ["id", "contact_id", "line1", "country", "postcode"]
      properties:
        id:
          type: "string"
          format: "uuid"
        contact_id:
          $ref: "#/components/schemas/contacts"
        line1:
          type: "string"
        country:
          type: "string"
          minLength: 2
          maxLength: 2
        postcode:
          type: "string"
