{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/pestprocrm-com/json-schema/pestprocrm-com-service-record-schema.json",
  "title": "ServiceRecord",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/pestprocrm-com-openapi.yml#/components/schemas/ServiceRecord",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique service record ID"
    },
    "customerId": {
      "type": "string",
      "description": "Customer ID"
    },
    "customerName": {
      "type": "string",
      "description": "Customer name"
    },
    "appointmentId": {
      "type": "string",
      "description": "Associated appointment ID"
    },
    "propertyId": {
      "type": "string",
      "description": "Property ID"
    },
    "address": {
      "type": "string",
      "description": "Service address"
    },
    "serviceType": {
      "type": "string",
      "enum": [
        "initial",
        "follow-up",
        "maintenance",
        "emergency"
      ],
      "description": "Type of service"
    },
    "pestType": {
      "type": "string",
      "enum": [
        "termites",
        "rodents",
        "ants",
        "cockroaches",
        "mosquitoes",
        "wildlife",
        "bed-bugs",
        "spiders",
        "wasps",
        "fleas",
        "ticks",
        "other"
      ],
      "description": "Type of pest treated"
    },
    "productsUsed": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ProductUsed"
      },
      "description": "Products applied during service"
    },
    "areasServiced": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AreaServiced"
      },
      "description": "Areas serviced"
    },
    "findings": {
      "type": "string",
      "description": "Description of what was found during inspection"
    },
    "recommendations": {
      "type": "string",
      "description": "Follow-up suggestions and recommendations"
    },
    "photos": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Photo URLs (before/after via Cloudinary)"
    },
    "waterReadings": {
      "$ref": "#/$defs/WaterReadings"
    },
    "chemicalDoses": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ChemicalDose"
      },
      "description": "Products added at the visit (pool verticals)"
    },
    "weatherConditions": {
      "$ref": "#/$defs/WeatherConditions"
    },
    "completedBy": {
      "type": "string",
      "description": "Technician ID who completed the service"
    },
    "completedAt": {
      "type": "string",
      "format": "date-time",
      "description": "When the service was completed"
    },
    "duration": {
      "type": "integer",
      "description": "Duration in minutes"
    },
    "customerSignature": {
      "type": "string",
      "description": "Customer signature (base64 or URL)"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "Created timestamp"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "Updated timestamp"
    }
  },
  "required": [
    "id",
    "customerId",
    "serviceType",
    "pestType"
  ],
  "$defs": {
    "AreaServiced": {
      "type": "object",
      "properties": {
        "location": {
          "type": "string",
          "enum": [
            "interior",
            "exterior",
            "attic",
            "crawlspace",
            "yard",
            "garage",
            "basement"
          ],
          "description": "Area location"
        },
        "notes": {
          "type": "string",
          "description": "Notes about this area"
        }
      },
      "required": [
        "location"
      ]
    },
    "ChemicalDose": {
      "type": "object",
      "description": "A product added at the visit (waterChemistry verticals).",
      "properties": {
        "product": {
          "type": "string",
          "description": "Product name as the operator calls it",
          "maxLength": 80
        },
        "amount": {
          "type": "number",
          "description": "Amount added"
        },
        "unit": {
          "type": "string",
          "enum": [
            "oz",
            "fl oz",
            "lb",
            "g",
            "kg",
            "ml",
            "L",
            "qt",
            "pt",
            "gal",
            "tab",
            "cup"
          ]
        }
      },
      "required": [
        "product",
        "amount",
        "unit"
      ]
    },
    "ProductUsed": {
      "type": "object",
      "properties": {
        "productName": {
          "type": "string",
          "description": "Name of the product used"
        },
        "EPA_registration": {
          "type": "string",
          "description": "EPA registration number"
        },
        "amount": {
          "type": "number",
          "description": "Amount of product used"
        },
        "unit": {
          "type": "string",
          "description": "Unit of measurement (oz, ml, gal, etc.)"
        },
        "applicationMethod": {
          "type": "string",
          "description": "Method of application (spray, bait, dust, etc.)"
        }
      },
      "required": [
        "productName"
      ]
    },
    "WaterReadings": {
      "type": "object",
      "description": "Pool water test at the visit (waterChemistry verticals). Numbers as read from the kit; ppm and mg/l are the same value.",
      "properties": {
        "freeChlorine": {
          "type": "number",
          "description": "Free chlorine, ppm / mg/l"
        },
        "ph": {
          "type": "number",
          "description": "pH"
        },
        "totalAlkalinity": {
          "type": "number",
          "description": "Total alkalinity, ppm / mg/l"
        },
        "cyanuricAcid": {
          "type": "number",
          "description": "Cyanuric acid (stabiliser), ppm / mg/l"
        },
        "calciumHardness": {
          "type": "number",
          "description": "Calcium hardness, ppm / mg/l"
        },
        "salt": {
          "type": "number",
          "description": "Salt, ppm / mg/l"
        },
        "waterTemp": {
          "type": "number",
          "description": "Water temperature"
        },
        "waterTempUnit": {
          "type": "string",
          "enum": [
            "F",
            "C"
          ],
          "description": "Stamped by the server from the operator country"
        }
      }
    },
    "WeatherConditions": {
      "type": "object",
      "properties": {
        "temp": {
          "type": "number",
          "description": "Temperature in Fahrenheit"
        },
        "humidity": {
          "type": "number",
          "description": "Humidity percentage"
        },
        "wind": {
          "type": "string",
          "description": "Wind conditions"
        }
      }
    }
  }
}