{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://app-protocol.org/schema/app-1.0.json",
  "title": "Applicant Profile Protocol (APP) v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["protocol", "basics"],
  "properties": {
    "protocol": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "id"],
      "properties": {
        "name": { "type": "string", "const": "ApplicantProfileProtocol" },
        "shortName": { "type": "string", "const": "APP" },
        "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
        "uri": { "type": "string", "format": "uri" },
        "id": { "type": "string" }
      }
    },
    "basics": { "$ref": "#/$defs/basics" },
    "experience": {
      "type": "array",
      "items": { "$ref": "#/$defs/experience" }
    },
    "education": {
      "type": "array",
      "items": { "$ref": "#/$defs/education" }
    },
    "skills": {
      "type": "array",
      "items": { "$ref": "#/$defs/skill" }
    },
    "projects": {
      "type": "array",
      "items": { "$ref": "#/$defs/project" }
    },
    "credentials": {
      "type": "array",
      "items": { "$ref": "#/$defs/credential" }
    },
    "languages": {
      "type": "array",
      "items": { "$ref": "#/$defs/language" }
    },
    "preferences": { "$ref": "#/$defs/preferences" },
    "metadata": { "$ref": "#/$defs/metadata" },
    "semantic": { "type": "object", "description": "Optional JSON-LD overlay", "additionalProperties": true },
    "enrichment": { "type": "object", "description": "Optional computed metrics", "additionalProperties": true },
    "evidence": {
      "type": "array",
      "items": { "$ref": "#/$defs/evidenceItem" }
    }
  },
  "$defs": {
    "dateYearMonth": {
      "type": "string",
      "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
    },
    "year": { "type": "string", "pattern": "^\\d{4}$" },
    "uri": { "type": "string", "format": "uri" },
    "email": { "type": "string", "format": "email" },
    "phone": { "type": "string", "minLength": 5, "maxLength": 30 },

    "personName": {
      "type": "object",
      "additionalProperties": false,
      "required": ["given", "family"],
      "properties": {
        "given": { "type": "string", "minLength": 1 },
        "family": { "type": "string", "minLength": 1 },
        "middle": { "type": "string" },
        "suffix": { "type": "string" }
      }
    },

    "location": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "country": { "type": "string", "minLength": 2 },
        "region": { "type": "string" },
        "city": { "type": "string" },
        "remote": { "type": "boolean" }
      }
    },

    "link": {
      "type": "object",
      "additionalProperties": false,
      "required": ["label", "url"],
      "properties": {
        "label": { "type": "string" },
        "url": { "$ref": "#/$defs/uri" }
      }
    },

    "contact": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "email": { "$ref": "#/$defs/email" },
        "phone": { "$ref": "#/$defs/phone" },
        "website": { "$ref": "#/$defs/uri" },
        "social": {
          "type": "array",
          "items": { "$ref": "#/$defs/link" }
        }
      }
    },

    "basics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name"],
      "properties": {
        "name": { "$ref": "#/$defs/personName" },
        "headline": { "type": "string", "maxLength": 200 },
        "summary": { "type": "string", "maxLength": 2000 },
        "location": { "$ref": "#/$defs/location" },
        "contact": { "$ref": "#/$defs/contact" },
        "links": {
          "type": "array",
          "items": { "$ref": "#/$defs/link" }
        }
      }
    },

    "organization": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "industry": { "type": "string" }
      }
    },

    "experience": {
      "type": "object",
      "additionalProperties": false,
      "required": ["role", "organization", "start"],
      "properties": {
        "role": { "type": "string" },
        "organization": { "$ref": "#/$defs/organization" },
        "start": { "$ref": "#/$defs/dateYearMonth" },
        "end": { "$ref": "#/$defs/dateYearMonth" },
        "current": { "type": "boolean" },
        "location": { "$ref": "#/$defs/location" },
        "employmentType": {
          "type": "string",
          "enum": ["Full-time", "Part-time", "Contract", "Internship", "Temporary"]
        },
        "highlights": {
          "type": "array",
          "items": { "type": "string", "maxLength": 500 }
        },
        "technologies": {
          "type": "array",
          "items": { "type": "string" }
        },
        "metrics": {
          "type": "object",
          "additionalProperties": true
        },
        "links": {
          "type": "array",
          "items": { "$ref": "#/$defs/link" }
        }
      }
    },

    "education": {
      "type": "object",
      "additionalProperties": false,
      "required": ["institution"],
      "properties": {
        "institution": { "type": "string" },
        "area": { "type": "string" },
        "degree": { "type": "string" },
        "start": { "$ref": "#/$defs/year" },
        "end": { "$ref": "#/$defs/year" },
        "completed": { "type": "boolean" },
        "grade": { "type": "string" },
        "links": {
          "type": "array",
          "items": { "$ref": "#/$defs/link" }
        }
      }
    },

    "skill": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "category": {
          "type": "string",
          "enum": [
            "ProgrammingLanguage",
            "Framework",
            "Library",
            "Tool",
            "CloudService",
            "Platform",
            "Datastore",
            "Methodology",
            "SoftSkill",
            "Domain"
          ]
        },
        "level": {
          "type": "string",
          "enum": ["Beginner", "Intermediate", "Advanced", "Expert"]
        },
        "years": { "type": "number", "minimum": 0, "maximum": 60 },
        "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
        "usage": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "lastUsed": { "$ref": "#/$defs/dateYearMonth" },
            "contexts": { "type": "array", "items": { "type": "string" } }
          }
        },
        "aliases": { "type": "array", "items": { "type": "string" } },
        "evidenceRef": { "type": "array", "items": { "type": "string" } }
      }
    },

    "project": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name"],
      "properties": {
        "name": { "type": "string" },
        "description": { "type": "string" },
        "role": { "type": "string" },
        "stack": { "type": "array", "items": { "type": "string" } },
        "links": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "website": { "$ref": "#/$defs/uri" },
            "repository": { "$ref": "#/$defs/uri" }
          }
        },
        "highlights": { "type": "array", "items": { "type": "string" } }
      }
    },

    "credential": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "issuer"],
      "properties": {
        "name": { "type": "string" },
        "issuer": { "type": "string" },
        "date": { "$ref": "#/$defs/dateYearMonth" },
        "id": { "type": "string" },
        "url": { "$ref": "#/$defs/uri" }
      }
    },

    "language": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "proficiency"],
      "properties": {
        "name": { "type": "string" },
        "proficiency": {
          "type": "string",
          "enum": ["Basic", "Conversational", "Professional", "Fluent", "Native"]
        }
      }
    },

    "preferences": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "employmentType": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["Full-time", "Part-time", "Contract", "Internship", "Temporary"]
          }
        },
        "workMode": {
          "type": "array",
          "items": { "type": "string", "enum": ["Onsite", "Remote", "Hybrid"] }
        },
        "relocation": { "type": "boolean" },
        "preferredLocations": { "type": "array", "items": { "type": "string" } }
      }
    },

    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "created": { "type": "string", "format": "date-time" },
        "updated": { "type": "string", "format": "date-time" },
        "source": { "type": "string", "enum": ["SelfReported", "Imported", "Generated"] },
        "tags": { "type": "array", "items": { "type": "string" } }
      }
    },

    "evidenceItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type"],
      "properties": {
        "type": { "type": "string", "enum": ["Certificate", "URL", "Document", "Hash", "VerifiableCredential"] },
        "url": { "$ref": "#/$defs/uri" },
        "description": { "type": "string" },
        "hash": {
          "type": "object",
          "additionalProperties": false,
          "required": ["algorithm", "value"],
          "properties": {
            "algorithm": { "type": "string" },
            "value": { "type": "string" }
          }
        },
        "refId": { "type": "string" }
      }
    }
  }
}
