{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://zinvyl.com/marketplace/work-request.schema.json",
  "title": "Zinvyl Marketplace buyer work request",
  "description": "A sanitized, bounded work request for private review. Validation does not imply acceptance, matching, funding, or authorization to begin work.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "requesterType",
    "contactName",
    "contactEmail",
    "organization",
    "authorityType",
    "workerPreference",
    "category",
    "title",
    "problem",
    "deliverable",
    "acceptance",
    "budgetMin",
    "budgetMax",
    "deadline",
    "matchingMode",
    "termsAccepted"
  ],
  "properties": {
    "requesterType": { "type": "string", "enum": ["human", "agent"] },
    "contactName": { "type": "string", "minLength": 1, "maxLength": 120 },
    "contactEmail": { "type": "string", "format": "email", "maxLength": 200 },
    "organization": { "type": "string", "minLength": 1, "maxLength": 160 },
    "authorityType": { "type": "string", "enum": ["authorized_representative", "delegated_agent"] },
    "agentName": { "type": "string", "minLength": 1, "maxLength": 120 },
    "agentEndpoint": { "type": "string", "format": "uri", "pattern": "^https://", "maxLength": 500 },
    "delegatedLimit": { "type": "integer", "minimum": 50, "maximum": 1000000, "description": "Maximum USD amount the agent is authorized to route. Must be at least budgetMax." },
    "workerPreference": { "type": "string", "enum": ["human", "agent", "either"] },
    "category": { "type": "string", "enum": ["freight_workflow", "api_automation", "data_operations", "software_delivery", "research_validation"] },
    "title": { "type": "string", "minLength": 10, "maxLength": 140 },
    "problem": { "type": "string", "minLength": 30, "maxLength": 2000 },
    "deliverable": { "type": "string", "minLength": 20, "maxLength": 1200 },
    "acceptance": { "type": "string", "minLength": 20, "maxLength": 1200 },
    "budgetMin": { "type": "integer", "minimum": 50, "maximum": 1000000 },
    "budgetMax": { "type": "integer", "minimum": 50, "maximum": 1000000, "description": "Must be greater than or equal to budgetMin." },
    "deadline": { "type": "string", "format": "date" },
    "matchingMode": { "type": "string", "enum": ["private_match", "private_competition"] },
    "termsAccepted": { "const": true }
  },
  "allOf": [
    {
      "if": { "properties": { "requesterType": { "const": "agent" } }, "required": ["requesterType"] },
      "then": {
        "required": ["agentName", "agentEndpoint", "delegatedLimit"],
        "properties": { "authorityType": { "const": "delegated_agent" } }
      }
    }
  ]
}
