{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "version": "2.0.0",
  "$id": "https://schemas.ectropy.ai/pm/participant.schema.json",
  "title": "Participant Schema",
  "description": "Project stakeholders who interact with PM decisions, voxels, and inspections. Includes roles, authority levels, and contact information.",
  "type": "object",
  "required": [
    "$id",
    "$schema",
    "schemaVersion",
    "participantId",
    "name",
    "role"
  ],
  "definitions": {
    "graphMetadata": {
      "type": "object",
      "description": "Bidirectional graph traversal metadata",
      "properties": {
        "inEdges": {
          "type": "array",
          "items": {
            "$ref": "https://schemas.ectropy.ai/_definitions/urn.schema.json"
          },
          "uniqueItems": true
        },
        "outEdges": {
          "type": "array",
          "items": {
            "$ref": "https://schemas.ectropy.ai/_definitions/urn.schema.json"
          },
          "uniqueItems": true
        }
      }
    },
    "participantRole": {
      "type": "string",
      "enum": [
        "FIELD_WORKER",
        "FOREMAN",
        "SUPERINTENDENT",
        "PROJECT_MANAGER",
        "ARCHITECT",
        "ENGINEER",
        "OWNER_REP",
        "OWNER",
        "INSPECTOR",
        "SUBCONTRACTOR",
        "GENERAL_CONTRACTOR",
        "REGULATORY",
        "CONSULTANT"
      ]
    },
    "participantStatus": {
      "type": "string",
      "enum": [
        "ACTIVE",
        "INACTIVE",
        "PENDING",
        "REMOVED"
      ]
    }
  },
  "properties": {
    "$id": {
      "$ref": "https://schemas.ectropy.ai/_definitions/urn.schema.json",
      "description": "URN identifier. Pattern: urn:luhtech:{project}:participant:{participantId}"
    },
    "$schema": {
      "type": "string",
      "format": "uri",
      "description": "Schema declaration: the URI of the schema this instance follows."
    },
    "schemaVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "meta": {
      "type": "object",
      "properties": {
        "projectId": {
          "type": "string"
        },
        "sourceOfTruth": {
          "type": "string"
        },
        "lastUpdated": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "participantId": {
      "type": "string",
      "pattern": "^[a-z0-9-]+$",
      "description": "URL-safe participant identifier (e.g., john-doe-pm)"
    },
    "name": {
      "type": "string",
      "description": "Full name"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "phone": {
      "type": "string"
    },
    "role": {
      "$ref": "#/definitions/participantRole",
      "description": "Primary project role"
    },
    "additionalRoles": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/participantRole"
      },
      "description": "Additional roles this participant may hold"
    },
    "authorityLevel": {
      "type": "integer",
      "minimum": 0,
      "maximum": 6,
      "description": "Decision authority level (0-6)"
    },
    "authorityLevelRef": {
      "$ref": "https://schemas.ectropy.ai/_definitions/urn.schema.json",
      "description": "URN reference to authority level definition"
    },
    "status": {
      "$ref": "#/definitions/participantStatus",
      "default": "ACTIVE"
    },
    "company": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "owner",
            "gc",
            "subcontractor",
            "architect",
            "engineer",
            "consultant",
            "regulatory",
            "other"
          ]
        },
        "contractNumber": {
          "type": "string"
        }
      }
    },
    "certifications": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "issuingBody": {
            "type": "string"
          },
          "number": {
            "type": "string"
          },
          "expirationDate": {
            "type": "string",
            "format": "date"
          }
        }
      }
    },
    "assignedZones": {
      "type": "array",
      "description": "Project zones this participant is assigned to",
      "items": {
        "type": "object",
        "properties": {
          "building": {
            "type": "string"
          },
          "level": {
            "type": "string"
          },
          "zone": {
            "type": "string"
          }
        }
      }
    },
    "permissions": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "capture-decision",
          "approve-decision",
          "reject-decision",
          "escalate-decision",
          "modify-schedule",
          "view-costs",
          "modify-costs",
          "perform-inspection",
          "approve-inspection",
          "view-all-voxels",
          "modify-voxels",
          "admin"
        ]
      },
      "description": "Explicit permissions granted"
    },
    "notificationPreferences": {
      "type": "object",
      "properties": {
        "email": {
          "type": "boolean",
          "default": true
        },
        "sms": {
          "type": "boolean",
          "default": false
        },
        "push": {
          "type": "boolean",
          "default": true
        },
        "decisionEscalations": {
          "type": "boolean",
          "default": true
        },
        "inspectionReminders": {
          "type": "boolean",
          "default": true
        },
        "dailyDigest": {
          "type": "boolean",
          "default": false
        }
      }
    },
    "timestamps": {
      "type": "object",
      "properties": {
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "lastActiveAt": {
          "type": "string",
          "format": "date-time"
        },
        "invitedAt": {
          "type": "string",
          "format": "date-time"
        },
        "joinedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "graphMetadata": {
      "$ref": "#/definitions/graphMetadata"
    }
  },
  "additionalProperties": false
}
