{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://dashremix.com/spec/crm/1.1.0/crm@1.schema.json",
 "title": "crm@1 v1.1.0",
 "description": "One property per table (an array of rows). Generated from schema.sql by spec/build.py. Extension tables (x_<owner>_*) belong to forks and board-derived tables (d_*) to the board that rebuilds them; both are allowed as additional properties.",
 "type": "object",
 "properties": {
  "meta": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "key": {
      "type": "string"
     },
     "value": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "key"
    ],
    "additionalProperties": false
   }
  },
  "companies": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "company_id": {
      "type": "string"
     },
     "name": {
      "type": [
       "string",
       "null"
      ]
     },
     "segment": {
      "type": [
       "string",
       "null"
      ]
     },
     "lifecycle": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "lead",
       "customer",
       "former_customer",
       "other",
       "unknown",
       null
      ]
     },
     "renewal_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "company_id",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "contacts": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "contact_id": {
      "type": "string"
     },
     "company_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "role": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "decision_maker",
       "evaluator",
       "requester",
       "other",
       null
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "contact_id",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "deals": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "deal_id": {
      "type": "string"
     },
     "company_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "contact_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "kind": {
      "type": "string",
      "enum": [
       "sale",
       "proposal",
       "grant"
      ]
     },
     "label": {
      "type": [
       "string",
       "null"
      ]
     },
     "pipeline": {
      "type": [
       "string",
       "null"
      ]
     },
     "stage": {
      "type": [
       "string",
       "null"
      ]
     },
     "state": {
      "type": "string",
      "enum": [
       "open",
       "won",
       "lost",
       "unknown"
      ]
     },
     "created_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "stage_changed_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "expected_close_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "closed_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "amount": {
      "type": [
       "number",
       "null"
      ]
     },
     "awarded_amount": {
      "type": [
       "number",
       "null"
      ]
     },
     "currency": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^[A-Z]{3}$"
     },
     "probability": {
      "type": [
       "number",
       "null"
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "deal_id",
     "kind",
     "state",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "deal_stage_changes": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "change_id": {
      "type": "string"
     },
     "deal_id": {
      "type": "string"
     },
     "from_stage": {
      "type": [
       "string",
       "null"
      ]
     },
     "to_stage": {
      "type": "string"
     },
     "changed_on": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "changed_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "change_id",
     "deal_id",
     "to_stage",
     "changed_on",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "deal_milestones": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "milestone_id": {
      "type": "string"
     },
     "deal_id": {
      "type": "string"
     },
     "kind": {
      "type": "string",
      "enum": [
       "follow_up",
       "application_deadline",
       "decision",
       "report_due",
       "other"
      ]
     },
     "due_on": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "completed_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "milestone_id",
     "deal_id",
     "kind",
     "due_on",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "activities": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "activity_id": {
      "type": "string"
     },
     "company_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "contact_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "deal_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "kind": {
      "type": "string",
      "enum": [
       "call",
       "email",
       "meeting",
       "message",
       "task",
       "other"
      ]
     },
     "occurred_on": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "occurred_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "activity_id",
     "kind",
     "occurred_on",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "tickets": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "ticket_id": {
      "type": "string"
     },
     "company_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "contact_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": "string",
      "enum": [
       "open",
       "pending",
       "resolved",
       "closed",
       "unknown"
      ]
     },
     "priority": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "low",
       "normal",
       "high",
       "urgent",
       null
      ]
     },
     "topic": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_on": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "created_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "first_response_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "resolved_on": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "resolved_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "ticket_id",
     "status",
     "created_on",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "survey_responses": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "response_id": {
      "type": "string"
     },
     "survey_key": {
      "type": "string"
     },
     "company_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "contact_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "segment": {
      "type": [
       "string",
       "null"
      ]
     },
     "responded_on": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
     },
     "responded_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "nps_score": {
      "type": [
       "integer",
       "null"
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     }
    },
    "required": [
     "response_id",
     "survey_key",
     "responded_on",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "survey_response_themes": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "response_id": {
      "type": "string"
     },
     "theme": {
      "type": "string"
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "confidence": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "rule",
       "default",
       "detected",
       "manual",
       null
      ]
     }
    },
    "required": [
     "response_id",
     "theme",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "deal_stages": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "pipeline": {
      "type": "string"
     },
     "stage": {
      "type": "string"
     },
     "position": {
      "type": "integer"
     },
     "state": {
      "type": "string",
      "enum": [
       "open",
       "won",
       "lost",
       "unknown"
      ]
     },
     "probability": {
      "type": [
       "number",
       "null"
      ]
     },
     "source": {
      "type": "string"
     },
     "source_ref": {
      "type": "string"
     },
     "imported_at": {
      "type": "string"
     }
    },
    "required": [
     "pipeline",
     "stage",
     "position",
     "state",
     "source",
     "source_ref",
     "imported_at"
    ],
    "additionalProperties": false
   }
  },
  "import_issues": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "issue_id": {
      "type": "string"
     },
     "severity": {
      "type": "string",
      "enum": [
       "info",
       "warn",
       "error"
      ]
     },
     "kind": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "detail": {
      "type": "string"
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "handling": {
      "type": "string"
     }
    },
    "required": [
     "issue_id",
     "severity",
     "kind",
     "title",
     "detail",
     "handling"
    ],
    "additionalProperties": false
   }
  },
  "annotations": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "annotation_id": {
      "type": "string"
     },
     "target": {
      "type": "string"
     },
     "kind": {
      "type": "string"
     },
     "body": {
      "type": "string"
     },
     "author": {
      "type": [
       "string",
       "null"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": [
       "string",
       "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?Z$"
     },
     "data_hash": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "annotation_id",
     "target",
     "kind",
     "body"
    ],
    "additionalProperties": false
   }
  },
  "overrides": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "override_id": {
      "type": "string"
     },
     "table_name": {
      "type": "string"
     },
     "row_id": {
      "type": "string"
     },
     "field": {
      "type": "string"
     },
     "value": {
      "type": [
       "string",
       "null"
      ]
     },
     "source_ref": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "override_id",
     "table_name",
     "row_id",
     "field"
    ],
    "additionalProperties": false
   }
  },
  "metric_registry": {
   "type": "array",
   "items": {
    "type": "object",
    "properties": {
     "metric_id": {
      "type": "string"
     },
     "version": {
      "type": [
       "integer",
       "null"
      ]
     },
     "unit": {
      "type": [
       "string",
       "null"
      ]
     },
     "params": {
      "type": [
       "string",
       "null"
      ]
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "sql": {
      "type": [
       "string",
       "null"
      ]
     },
     "test": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "metric_id"
    ],
    "additionalProperties": false
   }
  }
 },
 "required": [
  "meta",
  "companies",
  "contacts",
  "deals",
  "activities",
  "tickets",
  "survey_responses"
 ],
 "patternProperties": {
  "^x_[a-z0-9_]+$": {
   "type": "array"
  },
  "^d_[a-z0-9_]+$": {
   "type": "array"
  }
 },
 "additionalProperties": false
}
