{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:coos:schema:MaintenanceRequest",
  "title": "MaintenanceRequest",
  "description": "A report of a maintenance issue or a request for work, raised by an owner, resident, council member or manager.",
  "type": "object",
  "x-domain": "maintenance",
  "x-status": "proposed",
  "x-since": "0.1.0-draft",
  "x-relationships": [
    {
      "field": "strataCorporationId",
      "target": "StrataCorporation",
      "cardinality": "one",
      "required": true
    },
    {
      "field": "reportedByPersonId",
      "target": "Person",
      "cardinality": "one",
      "required": false
    },
    {
      "field": "strataLotId",
      "target": "StrataLot",
      "cardinality": "one",
      "required": false
    },
    {
      "field": "assetId",
      "target": "CommonAsset",
      "cardinality": "one",
      "required": false
    }
  ],
  "x-validationRules": [
    "strataLotId is expected when locationType is strataLot."
  ],
  "x-legalReviewNotes": [
    "Responsibility for repairs inside strata lots depends on bylaws; the standard records location, not responsibility."
  ],
  "required": [
    "id",
    "strataCorporationId",
    "title",
    "reportedAt",
    "status"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Stable identifier of this MaintenanceRequest record."
    },
    "strataCorporationId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "The strata corporation this record belongs to.",
      "x-references": "StrataCorporation"
    },
    "title": {
      "type": "string",
      "description": "Short summary.",
      "minLength": 1,
      "maxLength": 200
    },
    "description": {
      "type": "string",
      "description": "Details of the issue.",
      "maxLength": 5000
    },
    "reportedAt": {
      "$ref": "urn:coos:schema:common#/$defs/DateTime",
      "description": "When the request was made."
    },
    "reportedByPersonId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Person who reported it, if shared.",
      "x-references": "Person"
    },
    "locationType": {
      "type": "string",
      "description": "Where the issue is.",
      "enum": [
        "commonProperty",
        "limitedCommonProperty",
        "strataLot"
      ],
      "x-enumDescriptions": {
        "commonProperty": "Common property.",
        "limitedCommonProperty": "Limited common property.",
        "strataLot": "Inside a strata lot."
      }
    },
    "strataLotId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Strata lot concerned, if any.",
      "x-references": "StrataLot"
    },
    "assetId": {
      "$ref": "urn:coos:schema:common#/$defs/Identifier",
      "description": "Asset concerned, if any.",
      "x-references": "CommonAsset"
    },
    "priority": {
      "type": "string",
      "description": "Urgency.",
      "enum": [
        "low",
        "normal",
        "high",
        "emergency"
      ],
      "x-enumDescriptions": {
        "low": "Low.",
        "normal": "Normal.",
        "high": "High.",
        "emergency": "Emergency: risk to safety or of significant damage."
      }
    },
    "status": {
      "type": "string",
      "description": "Current status.",
      "enum": [
        "submitted",
        "triaged",
        "inProgress",
        "resolved",
        "closed",
        "declined"
      ],
      "x-enumDescriptions": {
        "submitted": "Received.",
        "triaged": "Reviewed and prioritised.",
        "inProgress": "Work under way.",
        "resolved": "Work completed.",
        "closed": "Closed.",
        "declined": "Not actioned."
      }
    },
    "extensions": {
      "$ref": "urn:coos:schema:common#/$defs/Extensions",
      "description": "Implementation-specific data, namespaced by reverse domain."
    }
  }
}
