{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://skygate.network/schemas/structured-resume-export-v2.json",
  "title": "Skygate Structured Resume Export v2",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version", "generated_at", "source", "date_of_birth", "location",
    "skills", "languages", "experience", "education", "certifications", "custom_fields"
  ],
  "properties": {
    "schema_version": { "const": "2.0" },
    "generated_at": { "type": "string" },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "email", "phone", "summary", "address", "skills", "languages", "date_of_birth", "gender", "nationality", "social_media", "relocation"],
      "properties": {
        "name": { "$ref": "#/$defs/nullableString" },
        "email": { "$ref": "#/$defs/nullableString" },
        "phone": { "$ref": "#/$defs/nullableString" },
        "summary": { "$ref": "#/$defs/nullableString" },
        "address": { "$ref": "#/$defs/nullableString" },
        "skills": { "$ref": "#/$defs/nullableString" },
        "languages": { "$ref": "#/$defs/nullableString" },
        "date_of_birth": { "$ref": "#/$defs/nullableString" },
        "gender": { "$ref": "#/$defs/nullableString" },
        "nationality": { "$ref": "#/$defs/nullableString" },
        "social_media": { "$ref": "#/$defs/nullableString" },
        "relocation": { "$ref": "#/$defs/nullableString" }
      }
    },
    "date_of_birth": { "$ref": "#/$defs/normalizedFact" },
    "location": {
      "type": "object",
      "additionalProperties": false,
      "required": ["raw_value", "country_code", "city", "region", "resolution"],
      "properties": {
        "raw_value": { "$ref": "#/$defs/nullableString" },
        "country_code": { "$ref": "#/$defs/nullableString" },
        "city": { "$ref": "#/$defs/nullableString" },
        "region": { "$ref": "#/$defs/nullableString" },
        "resolution": { "$ref": "#/$defs/resolution" }
      }
    },
    "skills": {
      "type": "array",
      "items": { "$ref": "#/$defs/skill" }
    },
    "languages": {
      "type": "array",
      "items": { "$ref": "#/$defs/language" }
    },
    "experience": {
      "type": "array",
      "items": { "$ref": "#/$defs/experience" }
    },
    "education": {
      "type": "array",
      "items": { "$ref": "#/$defs/education" }
    },
    "certifications": {
      "type": "array",
      "items": { "$ref": "#/$defs/certification" }
    },
    "custom_fields": {
      "type": "array",
      "items": { "$ref": "#/$defs/customField" }
    }
  },
  "$defs": {
    "nullableString": { "type": ["string", "null"] },
    "nullableNumber": { "type": ["number", "null"] },
    "nullableBoolean": { "type": ["boolean", "null"] },
    "resolution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "source", "provider", "model", "version", "confidence", "alternatives", "notes", "verified_at"],
      "properties": {
        "state": { "$ref": "#/$defs/nullableString" },
        "source": { "$ref": "#/$defs/nullableString" },
        "provider": { "$ref": "#/$defs/nullableString" },
        "model": { "$ref": "#/$defs/nullableString" },
        "version": { "$ref": "#/$defs/nullableString" },
        "confidence": { "$ref": "#/$defs/nullableNumber" },
        "alternatives": { "type": "array" },
        "notes": { "$ref": "#/$defs/nullableString" },
        "verified_at": { "$ref": "#/$defs/nullableString" }
      }
    },
    "normalizedFact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["raw_value", "date", "precision", "resolution"],
      "properties": {
        "raw_value": { "$ref": "#/$defs/nullableString" },
        "date": { "$ref": "#/$defs/nullableString" },
        "precision": { "$ref": "#/$defs/nullableString" },
        "resolution": { "$ref": "#/$defs/resolution" }
      }
    },
    "proficiency": {
      "type": "object",
      "additionalProperties": false,
      "required": ["raw_value", "code"],
      "properties": {
        "raw_value": { "$ref": "#/$defs/nullableString" },
        "code": { "$ref": "#/$defs/nullableString" }
      }
    },
    "publicSourceLocator": {
      "type": "object",
      "additionalProperties": true
    },
    "skillEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_section", "text", "confidence", "source_locator"],
      "properties": {
        "source_section": { "$ref": "#/$defs/nullableString" },
        "text": { "$ref": "#/$defs/nullableString" },
        "confidence": { "$ref": "#/$defs/nullableNumber" },
        "source_locator": { "$ref": "#/$defs/publicSourceLocator" }
      }
    },
    "skill": {
      "type": "object",
      "additionalProperties": false,
      "required": ["raw_name", "normalized_name", "category", "taxonomy", "proficiency", "experience", "resolution", "evidence"],
      "properties": {
        "raw_name": { "type": "string" },
        "normalized_name": { "type": "string" },
        "category": { "$ref": "#/$defs/nullableString" },
        "taxonomy": {
          "type": "object",
          "additionalProperties": false,
          "required": ["namespace", "version", "external_id", "preferred_label", "lifecycle_state"],
          "properties": {
            "namespace": { "$ref": "#/$defs/nullableString" },
            "version": { "$ref": "#/$defs/nullableString" },
            "external_id": { "$ref": "#/$defs/nullableString" },
            "preferred_label": { "$ref": "#/$defs/nullableString" },
            "lifecycle_state": { "$ref": "#/$defs/nullableString" }
          }
        },
        "proficiency": { "$ref": "#/$defs/proficiency" },
        "experience": {
          "type": "object",
          "additionalProperties": false,
          "required": ["months", "status", "last_used_on", "currently_used"],
          "properties": {
            "months": { "type": ["integer", "null"] },
            "status": { "type": "string" },
            "last_used_on": { "$ref": "#/$defs/nullableString" },
            "currently_used": { "type": "boolean" }
          }
        },
        "resolution": { "$ref": "#/$defs/resolution" },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/skillEvidence" } }
      }
    },
    "language": {
      "type": "object",
      "additionalProperties": false,
      "required": ["raw_name", "canonical_name", "language_code", "proficiency", "resolution", "evidence"],
      "properties": {
        "raw_name": { "type": "string" },
        "canonical_name": { "type": "string" },
        "language_code": { "$ref": "#/$defs/nullableString" },
        "proficiency": { "$ref": "#/$defs/proficiency" },
        "resolution": { "$ref": "#/$defs/resolution" },
        "evidence": {
          "type": "object",
          "additionalProperties": false,
          "required": ["source_section", "text", "source_locator"],
          "properties": {
            "source_section": { "$ref": "#/$defs/nullableString" },
            "text": { "$ref": "#/$defs/nullableString" },
            "source_locator": { "$ref": "#/$defs/publicSourceLocator" }
          }
        }
      }
    },
    "experience": {
      "type": "object",
      "additionalProperties": false,
      "required": ["company", "positions"],
      "properties": {
        "company": { "$ref": "#/$defs/nullableString" },
        "positions": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["designation", "raw_date_range", "start_on", "end_on", "current_role", "date_precision", "date_resolution", "city", "country", "responsibilities"],
            "properties": {
              "designation": { "$ref": "#/$defs/nullableString" },
              "raw_date_range": { "$ref": "#/$defs/nullableString" },
              "start_on": { "$ref": "#/$defs/nullableString" },
              "end_on": { "$ref": "#/$defs/nullableString" },
              "current_role": { "type": "boolean" },
              "date_precision": { "$ref": "#/$defs/nullableString" },
              "date_resolution": { "$ref": "#/$defs/resolution" },
              "city": { "$ref": "#/$defs/nullableString" },
              "country": { "$ref": "#/$defs/nullableString" },
              "responsibilities": { "type": "array", "items": { "type": "string" } }
            }
          }
        }
      }
    },
    "education": {
      "type": "object",
      "additionalProperties": false,
      "required": ["institution", "location", "degree_original", "field_of_study", "graduation_original", "dates", "degree_classification", "gpa"],
      "properties": {
        "institution": { "$ref": "#/$defs/nullableString" },
        "location": { "$ref": "#/$defs/nullableString" },
        "degree_original": { "$ref": "#/$defs/nullableString" },
        "field_of_study": { "$ref": "#/$defs/nullableString" },
        "graduation_original": { "$ref": "#/$defs/nullableString" },
        "dates": {
          "type": "object",
          "additionalProperties": false,
          "required": ["start_on", "end_on", "graduated_on", "currently_enrolled", "precision", "resolution"],
          "properties": {
            "start_on": { "$ref": "#/$defs/nullableString" },
            "end_on": { "$ref": "#/$defs/nullableString" },
            "graduated_on": { "$ref": "#/$defs/nullableString" },
            "currently_enrolled": { "type": "boolean" },
            "precision": { "$ref": "#/$defs/nullableString" },
            "resolution": { "$ref": "#/$defs/resolution" }
          }
        },
        "degree_classification": {
          "type": "object",
          "additionalProperties": false,
          "required": ["code", "label", "isced_level", "resolution"],
          "properties": {
            "code": { "$ref": "#/$defs/nullableString" },
            "label": { "$ref": "#/$defs/nullableString" },
            "isced_level": { "$ref": "#/$defs/nullableString" },
            "resolution": { "$ref": "#/$defs/resolution" }
          }
        },
        "gpa": {
          "type": "object",
          "additionalProperties": false,
          "required": ["raw_value", "value", "scale"],
          "properties": {
            "raw_value": { "$ref": "#/$defs/nullableString" },
            "value": { "$ref": "#/$defs/nullableNumber" },
            "scale": { "$ref": "#/$defs/nullableNumber" }
          }
        }
      }
    },
    "certification": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name_original", "issuer", "legacy_date_text", "normalized_name", "normalized_code", "dates", "credential"],
      "properties": {
        "name_original": { "$ref": "#/$defs/nullableString" },
        "issuer": { "$ref": "#/$defs/nullableString" },
        "legacy_date_text": { "$ref": "#/$defs/nullableString" },
        "normalized_name": { "$ref": "#/$defs/nullableString" },
        "normalized_code": { "$ref": "#/$defs/nullableString" },
        "dates": {
          "type": "object",
          "additionalProperties": false,
          "required": ["raw_issued_date", "issued_on", "issued_precision", "raw_valid_from", "valid_from_on", "valid_from_precision", "raw_expires_date", "expires_on", "expires_precision", "current_credential", "resolution"],
          "properties": {
            "raw_issued_date": { "$ref": "#/$defs/nullableString" },
            "issued_on": { "$ref": "#/$defs/nullableString" },
            "issued_precision": { "$ref": "#/$defs/nullableString" },
            "raw_valid_from": { "$ref": "#/$defs/nullableString" },
            "valid_from_on": { "$ref": "#/$defs/nullableString" },
            "valid_from_precision": { "$ref": "#/$defs/nullableString" },
            "raw_expires_date": { "$ref": "#/$defs/nullableString" },
            "expires_on": { "$ref": "#/$defs/nullableString" },
            "expires_precision": { "$ref": "#/$defs/nullableString" },
            "current_credential": { "$ref": "#/$defs/nullableBoolean" },
            "resolution": { "$ref": "#/$defs/resolution" }
          }
        },
        "credential": {
          "type": "object",
          "additionalProperties": false,
          "required": ["id", "url"],
          "properties": {
            "id": { "$ref": "#/$defs/nullableString" },
            "url": { "$ref": "#/$defs/nullableString" }
          }
        }
      }
    },
    "customField": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "label", "field_type", "allowed_values", "searchable", "requires_evidence", "value", "value_text", "confidence", "evidence", "source_section", "source_provider", "source_model", "verification_state", "verified_at"],
      "properties": {
        "key": { "type": "string" },
        "label": { "type": "string" },
        "field_type": { "type": "string" },
        "allowed_values": { "type": "array" },
        "searchable": { "type": "boolean" },
        "requires_evidence": { "type": "boolean" },
        "value": {},
        "value_text": { "type": "string" },
        "confidence": { "$ref": "#/$defs/nullableNumber" },
        "evidence": { "$ref": "#/$defs/nullableString" },
        "source_section": { "$ref": "#/$defs/nullableString" },
        "source_provider": { "$ref": "#/$defs/nullableString" },
        "source_model": { "$ref": "#/$defs/nullableString" },
        "verification_state": { "enum": ["verified", "not_verified"] },
        "verified_at": { "$ref": "#/$defs/nullableString" }
      }
    }
  }
}
