# OAIS Archival Information Package (AIP) Schema
# Based on REF-061 OAIS Reference Model
# Issue: #133

$schema: "https://json-schema.org/draft/2020-12/schema"
$id: "https://aiwg.io/schemas/oais-aip/v1"
title: "OAIS Archival Information Package Schema"
description: |
  Schema for OAIS-compliant Archival Information Packages.
  Provides complete preservation metadata and chain-of-custody
  for research sources and generated artifacts.

type: object
required:
  - aip_id
  - content_information
  - preservation_description_information

properties:
  aip_id:
    type: string
    format: uuid
    description: "Unique AIP identifier"

  created_at:
    type: string
    format: date-time

  updated_at:
    type: string
    format: date-time

  status:
    type: string
    enum:
      - draft
      - submitted
      - archived
      - deprecated
    default: draft

  content_information:
    $ref: "#/$defs/ContentInformation"
    description: "The actual content being preserved"

  preservation_description_information:
    $ref: "#/$defs/PDI"
    description: "Information needed to preserve content"

  packaging_information:
    $ref: "#/$defs/PackagingInformation"
    description: "How AIP is packaged"

  descriptive_information:
    $ref: "#/$defs/DescriptiveInformation"
    description: "Discovery and access metadata"

$defs:
  ContentInformation:
    type: object
    required:
      - content_object
      - representation_information
    properties:
      content_object:
        type: object
        properties:
          type:
            type: string
            enum:
              - research_paper
              - generated_artifact
              - source_code
              - documentation
          path:
            type: string
          format:
            type: string
            examples: ["application/pdf", "text/markdown", "text/typescript"]
          size_bytes:
            type: integer
          checksum:
            type: object
            properties:
              algorithm:
                type: string
                enum: [sha256, sha512, md5]
              value:
                type: string

      representation_information:
        type: object
        properties:
          structure:
            type: object
            description: "How bits map to content"
          semantics:
            type: object
            description: "What content means"
          other:
            type: object
            description: "Additional interpretation info"

  PDI:
    type: object
    description: "Preservation Description Information"
    properties:
      reference_information:
        type: object
        description: "Identifiers for content"
        properties:
          identifiers:
            type: array
            items:
              type: object
              properties:
                type:
                  type: string
                  enum: [doi, arxiv, isbn, issn, ref_id, uuid]
                value:
                  type: string

      provenance_information:
        type: object
        description: "History and chain-of-custody"
        properties:
          origin:
            type: object
            properties:
              source:
                type: string
              acquisition_date:
                type: string
                format: date-time
              acquisition_method:
                type: string
                enum: [download, upload, generation, derivation]
          custody_history:
            type: array
            items:
              type: object
              properties:
                timestamp:
                  type: string
                  format: date-time
                event:
                  type: string
                agent:
                  type: string
                details:
                  type: string

      context_information:
        type: object
        description: "Why content is being preserved"
        properties:
          purpose:
            type: string
          relationships:
            type: array
            items:
              type: object
              properties:
                type:
                  type: string
                  enum: [cites, cited_by, derives_from, source_of, implements, documents]
                target:
                  type: string
          collection:
            type: string
            description: "Collection this belongs to"

      fixity_information:
        type: object
        description: "Data integrity verification"
        properties:
          checksums:
            type: array
            items:
              type: object
              properties:
                algorithm:
                  type: string
                value:
                  type: string
                computed_at:
                  type: string
                  format: date-time
          last_verified:
            type: string
            format: date-time
          verification_history:
            type: array
            items:
              type: object
              properties:
                timestamp:
                  type: string
                  format: date-time
                result:
                  type: string
                  enum: [pass, fail]
                details:
                  type: string

      access_rights_information:
        type: object
        description: "Who can access and how"
        properties:
          license:
            type: object
            properties:
              type:
                type: string
              url:
                type: string
          access_level:
            type: string
            enum: [public, internal, restricted, confidential]
          restrictions:
            type: array
            items:
              type: string

  PackagingInformation:
    type: object
    properties:
      format:
        type: string
        enum: [directory, tar, zip, bagit]
        default: directory
      structure:
        type: object
        properties:
          manifest_path:
            type: string
            default: "manifest.json"
          content_path:
            type: string
            default: "content/"
          metadata_path:
            type: string
            default: "metadata/"

  DescriptiveInformation:
    type: object
    description: "Discovery metadata"
    properties:
      title:
        type: string
      description:
        type: string
      creators:
        type: array
        items:
          type: string
      subjects:
        type: array
        items:
          type: string
      dates:
        type: object
        properties:
          created:
            type: string
            format: date-time
          modified:
            type: string
            format: date-time
          published:
            type: string
            format: date
      coverage:
        type: object
        properties:
          temporal:
            type: string
          spatial:
            type: string

# Package structure
package_structure:
  description: "Standard AIP directory structure"
  layout: |
    AIP-{id}/
    ├── manifest.json           # This AIP schema instance
    ├── content/
    │   ├── original/           # Original files
    │   │   └── paper.pdf
    │   └── derived/            # Derived representations
    │       └── paper.md
    ├── metadata/
    │   ├── pdi.json           # Preservation Description Information
    │   ├── provenance.json    # Full provenance chain
    │   └── dc.xml             # Dublin Core metadata
    └── logs/
        └── fixity.log         # Verification history

# Agent protocol
agent_protocol:
  create_aip:
    description: "Create new AIP for content"
    steps:
      - validate_content
      - compute_checksums
      - extract_metadata
      - build_pdi
      - create_package
      - validate_package

  ingest_aip:
    description: "Ingest new content as AIP"
    steps:
      - receive_sip (Submission Information Package)
      - validate_sip
      - transform_to_aip
      - store_aip
      - index_for_discovery

  access_aip:
    description: "Generate DIP from AIP"
    steps:
      - verify_access_rights
      - verify_fixity
      - create_dip (Dissemination Information Package)
      - deliver_to_user

  verify_aip:
    description: "Verify AIP integrity"
    schedule: weekly
    steps:
      - load_manifest
      - verify_all_checksums
      - report_results
      - update_verification_history

# Storage locations
storage:
  research_aips: ".aiwg/research/aips/"
  artifact_aips: ".aiwg/artifacts/aips/"
  index: ".aiwg/research/aips/index.json"

# Examples
examples:
  research_paper_aip:
    aip_id: "aip-ref-056-001"
    content_information:
      content_object:
        type: research_paper
        path: "content/original/fair-principles.pdf"
        format: "application/pdf"
        size_bytes: 1250000
        checksum:
          algorithm: sha256
          value: "abc123..."
      representation_information:
        structure:
          format: "PDF 1.7"
        semantics:
          domain: "data management"
          language: "en"
    preservation_description_information:
      reference_information:
        identifiers:
          - type: doi
            value: "10.1038/sdata.2016.18"
          - type: ref_id
            value: "REF-056"
      provenance_information:
        origin:
          source: "https://doi.org/10.1038/sdata.2016.18"
          acquisition_date: "2026-01-15T10:00:00Z"
          acquisition_method: download
      fixity_information:
        checksums:
          - algorithm: sha256
            value: "abc123..."
            computed_at: "2026-01-15T10:00:00Z"
        last_verified: "2026-01-25T00:00:00Z"
      access_rights_information:
        license:
          type: CC-BY-4.0
          url: "https://creativecommons.org/licenses/by/4.0/"
        access_level: public

# References
references:
  research:
    - "@.aiwg/research/findings/REF-061-oais.md"
  implementation:
    - "#133"
  related:
    - "@agentic/code/frameworks/sdlc-complete/schemas/research/fixity-manifest.yaml"
    - "@agentic/code/frameworks/sdlc-complete/schemas/research/bibtex-export.yaml"
