{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "CreateOrderRequest": {
      "$id": "CreateOrderRequest",
      "type": "object",
      "required": ["reference_number", "parameters"],
      "properties": {
        "reference_number": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "description": "Client-supplied unique identifier for idempotency"
        },
        "webhook_url": {
          "type": "string",
          "format": "uri",
          "description": "URL to POST results when order completes"
        },
        "parameters": {
          "$ref": "#/definitions/RecordSearchParameters"
        },
        "options": {
          "$ref": "#/definitions/OrderOptions"
        }
      },
      "additionalProperties": false
    },

    "RecordSearchParameters": {
      "$id": "RecordSearchParameters",
      "type": "object",
      "required": ["service_type", "service_name", "first_name", "last_name", "date_of_birth"],
      "properties": {
        "service_type": {
          "type": "string",
          "enum": ["criminal"],
          "description": "Type of search to perform"
        },
        "service_name": {
          "type": "string",
          "enum": ["CountyCriminal", "StatewideCriminal", "NationwideFederalCriminal", "StatewideFederalCriminal", "DistrictFederalCriminal"],
          "description": "Specific service/product name"
        },
        "service_code": {
          "type": "string",
          "maxLength": 50,
          "description": "Client-specific package code (configured during account setup)"
        },
        "first_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50,
          "description": "Subject's first name"
        },
        "middle_name": {
          "type": "string",
          "maxLength": 50,
          "description": "Subject's middle name (optional)"
        },
        "last_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50,
          "description": "Subject's last name"
        },
        "suffix": {
          "type": "string",
          "maxLength": 10,
          "description": "Name suffix (Jr., Sr., III, etc.)"
        },
        "date_of_birth": {
          "type": "string",
          "format": "date",
          "description": "Date of birth in YYYY-MM-DD format"
        },
        "ssn": {
          "type": "string",
          "minLength": 4,
          "maxLength": 11,
          "description": "Social Security Number (optional, may include dashes)"
        },
        "driver_license_number": {
          "type": "string",
          "maxLength": 25,
          "description": "Driver's license number"
        },
        "driver_license_state": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "Driver's license issuing state (2-letter code)"
        },
        "email_address": {
          "type": "string",
          "format": "email",
          "description": "Subject's email address"
        },
        "addresses": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Address"
          },
          "maxItems": 10,
          "description": "Array of subject addresses"
        },
        "aliases": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Alias"
          },
          "maxItems": 20,
          "description": "Array of known aliases"
        },
        "state": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "2-letter UPPERCASE state code"
        },
        "county": {
          "type": "string",
          "pattern": "^[A-Z0-9 \\-\\.]+$",
          "description": "County name in UPPERCASE"
        },
        "district": {
          "type": "string",
          "pattern": "^[A-Z0-9 \\-\\.]+$",
          "description": "Federal district in UPPERCASE"
        },
        "crim_watch": {
          "type": "boolean",
          "default": false,
          "description": "Enable continuous monitoring"
        },
        "crim_watch_frequency": {
          "type": "string",
          "enum": ["MONTHLY", "EVERY_3_MONTHS", "EVERY_6_MONTHS", "YEARLY"],
          "description": "Monitoring frequency (required if crim_watch=true)"
        }
      },
      "additionalProperties": false
    },

    "OrderOptions": {
      "$id": "OrderOptions",
      "type": "object",
      "properties": {
        "test_mode": {
          "type": "boolean",
          "default": false,
          "description": "Enable test mode for sandbox testing"
        },
        "search_years": {
          "type": "integer",
          "minimum": 1,
          "maximum": 99,
          "default": 7,
          "description": "Number of years to search"
        },
        "special_instructions": {
          "type": "string",
          "maxLength": 2000,
          "description": "Special instructions for the search"
        },
        "court_docs_requested": {
          "type": "boolean",
          "default": false,
          "description": "Request court documents if available"
        },
        "rush_requested": {
          "type": "boolean",
          "default": false,
          "description": "Request expedited processing"
        }
      },
      "additionalProperties": false
    },

    "Address": {
      "$id": "Address",
      "type": "object",
      "properties": {
        "street_address": {
          "type": "string",
          "maxLength": 200,
          "description": "Street address line 1"
        },
        "street_address_2": {
          "type": "string",
          "maxLength": 100,
          "description": "Street address line 2 (apt, suite, etc.)"
        },
        "city": {
          "type": "string",
          "maxLength": 100,
          "description": "City name"
        },
        "state": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "2-letter state code"
        },
        "zip_code": {
          "type": "string",
          "maxLength": 20,
          "description": "ZIP/postal code"
        },
        "country": {
          "type": "string",
          "maxLength": 2,
          "default": "US",
          "description": "Country code"
        },
        "address_type": {
          "type": "string",
          "enum": ["current", "previous", "mailing"],
          "description": "Type of address"
        }
      },
      "additionalProperties": false
    },

    "Alias": {
      "$id": "Alias",
      "type": "object",
      "required": ["first_name", "last_name"],
      "properties": {
        "first_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50,
          "description": "Alias first name"
        },
        "middle_name": {
          "type": "string",
          "maxLength": 50,
          "description": "Alias middle name (optional)"
        },
        "last_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50,
          "description": "Alias last name"
        }
      },
      "additionalProperties": false
    },

    "OrderResultResponse": {
      "$id": "OrderResultResponse",
      "type": "object",
      "required": ["order_id", "reference_number", "status", "status_message", "timestamp"],
      "properties": {
        "order_id": {
          "type": "string",
          "description": "InfoCheck order identifier"
        },
        "reference_number": {
          "type": "string",
          "description": "Client reference number"
        },
        "status": {
          "type": "string",
          "enum": ["Pending", "Complete", "Failed", "Cancelled"],
          "description": "Order processing status"
        },
        "status_message": {
          "type": "string",
          "description": "Human-readable status description"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "Response timestamp in ISO 8601 format"
        },
        "report_link": {
          "type": "string",
          "format": "uri",
          "description": "URL to view PDF report"
        },
        "recommendation": {
          "type": "string",
          "description": "Adjudication recommendation"
        },
        "alerts": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Array of order IDs with discrepancies"
        },
        "pricing": {
          "$ref": "#/definitions/Pricing"
        },
        "result": {
          "$ref": "#/definitions/RecordSearchResult"
        }
      }
    },

    "Pricing": {
      "$id": "Pricing",
      "type": "object",
      "properties": {
        "total_price": {
          "type": "number",
          "description": "Total price including court fees"
        },
        "total_price_minus_court_fees": {
          "type": "number",
          "description": "Total price excluding court fees"
        },
        "total_court_fees": {
          "type": "number",
          "description": "Total court fees"
        },
        "currency": {
          "type": "string",
          "default": "USD",
          "description": "Currency code"
        }
      }
    },

    "RecordSearchResult": {
      "$id": "RecordSearchResult",
      "type": "object",
      "required": ["result_type", "result_status", "service_type", "service_name", "subject", "case_count", "records"],
      "properties": {
        "result_type": {
          "type": "string",
          "const": "RecordSearchResult"
        },
        "result_status": {
          "type": "string",
          "enum": ["NO_RECORD", "RECORD", "RECORD_AVAILABLE", "ERROR"],
          "description": "Result status"
        },
        "service_type": {
          "type": "string",
          "enum": ["criminal"]
        },
        "service_name": {
          "type": "string"
        },
        "service_code": {
          "type": "string"
        },
        "jurisdiction": {
          "type": "object",
          "properties": {
            "state": { "type": "string" },
            "county": { "type": "string" },
            "district": { "type": "string" }
          }
        },
        "subject": {
          "type": "object",
          "properties": {
            "first_name": { "type": "string" },
            "middle_name": { "type": "string" },
            "last_name": { "type": "string" },
            "suffix": { "type": "string" },
            "date_of_birth": { "type": "string" }
          }
        },
        "case_count": {
          "type": "integer",
          "minimum": 0
        },
        "closing_comments": {
          "type": "string"
        },
        "records": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CriminalRecord"
          }
        },
        "fees": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Fee"
          }
        },
        "crim_watch": {
          "$ref": "#/definitions/CrimWatchInfo"
        }
      }
    },

    "CriminalRecord": {
      "$id": "CriminalRecord",
      "type": "object",
      "properties": {
        "verified_by": {
          "type": "object",
          "properties": {
            "first_name": { "type": "boolean" },
            "middle_name": { "type": "boolean" },
            "last_name": { "type": "boolean" },
            "date_of_birth": { "type": "boolean" }
          },
          "description": "Fields used to verify identity match"
        },
        "on_file_details": {
          "type": "object",
          "properties": {
            "first_name": { "type": "string" },
            "middle_name": { "type": "string" },
            "last_name": { "type": "string" },
            "date_of_birth": { "type": "string" },
            "ssn": { "type": "string" },
            "ethnicity": { "type": "string" },
            "address": { "type": "string" },
            "aliases": { "type": "string" },
            "additional_id_info": { "type": "string" }
          },
          "description": "Information as found on file"
        },
        "case_number": {
          "type": "string",
          "description": "Court case number"
        },
        "court": {
          "type": "string",
          "description": "Court name"
        },
        "arrest_date": {
          "type": "string",
          "format": "date",
          "description": "Arrest date"
        },
        "file_date": {
          "type": "string",
          "format": "date",
          "description": "Case file date"
        },
        "disposition_date": {
          "type": "string",
          "format": "date",
          "description": "Case disposition date"
        },
        "offense_date": {
          "type": "string",
          "format": "date",
          "description": "Date offense occurred"
        },
        "arresting_agency": {
          "type": "string",
          "description": "Arresting agency name"
        },
        "case_comments": {
          "type": "string",
          "description": "Comments about the case"
        },
        "counts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Offense"
          },
          "description": "Array of offense/count details"
        },
        "source_name": {
          "type": "string",
          "description": "Record source"
        },
        "matched_by": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Fields used for matching"
        }
      }
    },

    "Offense": {
      "$id": "Offense",
      "type": "object",
      "properties": {
        "offense": {
          "type": "string",
          "description": "Offense description"
        },
        "crime_type": {
          "type": "string",
          "description": "Offense level (FELONY, MISDEMEANOR, etc.)"
        },
        "statute": {
          "type": "string",
          "description": "Statute code"
        },
        "disposition": {
          "type": "string",
          "description": "Case disposition"
        },
        "disposition_date": {
          "type": "string",
          "format": "date",
          "description": "Disposition date"
        },
        "fine": {
          "type": "number",
          "description": "Fine amount"
        },
        "court_fee": {
          "type": "number",
          "description": "Court fee amount"
        },
        "restitution": {
          "type": "string",
          "description": "Restitution amount/details"
        },
        "plea": {
          "type": "string",
          "description": "Plea entered"
        },
        "sentence": {
          "$ref": "#/definitions/Sentence"
        },
        "offense_comments": {
          "type": "string",
          "description": "Comments about this count"
        }
      }
    },

    "Sentence": {
      "$id": "Sentence",
      "type": "object",
      "properties": {
        "probation": {
          "type": "string",
          "description": "Probation sentence"
        },
        "jail": {
          "type": "string",
          "description": "Jail time"
        },
        "prison": {
          "type": "string",
          "description": "Prison time"
        },
        "jail_suspended_time": {
          "type": "string",
          "description": "Suspended jail time"
        },
        "jail_credit_time": {
          "type": "string",
          "description": "Credited jail time"
        },
        "prison_suspended_time": {
          "type": "string",
          "description": "Suspended prison time"
        },
        "prison_credit_time": {
          "type": "string",
          "description": "Credited prison time"
        },
        "community_service": {
          "type": "string",
          "description": "Community service"
        },
        "sentence_other": {
          "type": "string",
          "description": "Other sentence details"
        }
      }
    },

    "Fee": {
      "$id": "Fee",
      "type": "object",
      "properties": {
        "fee_type": {
          "type": "string",
          "description": "Type of fee"
        },
        "description": {
          "type": "string",
          "description": "Fee description"
        },
        "amount": {
          "type": "number",
          "description": "Fee amount"
        },
        "currency": {
          "type": "string",
          "default": "USD",
          "description": "Currency code"
        }
      }
    },

    "CrimWatchInfo": {
      "$id": "CrimWatchInfo",
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "frequency": {
          "type": "string",
          "enum": ["MONTHLY", "EVERY_3_MONTHS", "EVERY_6_MONTHS", "YEARLY"]
        },
        "monitor_id": {
          "type": "string"
        },
        "next_run_date": {
          "type": "string",
          "format": "date"
        }
      }
    },

    "ErrorResponse": {
      "$id": "ErrorResponse",
      "type": "object",
      "required": ["error"],
      "properties": {
        "error": {
          "type": "object",
          "required": ["code", "message"],
          "properties": {
            "code": {
              "type": "string",
              "description": "Error code"
            },
            "message": {
              "type": "string",
              "description": "Human-readable error message"
            },
            "details": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "field": { "type": "string" },
                  "issue": { "type": "string" }
                }
              },
              "description": "Field-level error details"
            },
            "request_id": {
              "type": "string",
              "description": "Request tracking ID"
            }
          }
        }
      }
    }
  }
}
