{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/akahu/main/json-schema/akahu-report-data-source-schema.json",
  "title": "ReportDataSource",
  "description": "A Data Source represents a single data input, such as an individual bank statement. A Resource may map to one or more Data Sources (for example a PDF that includes multiple bank statements would be one resource containing multiple data sources).",
  "x-generated": "2026-10-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akahu-reports-api-openapi.yml#/components/schemas/ReportDataSource",
  "type": "object",
  "properties": {
    "_id": {
      "$ref": "#/$defs/ReportDataSourceId"
    },
    "_account": {
      "$ref": "#/$defs/ReportAccountId"
    },
    "provider": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "_id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "logo": {
          "type": "string",
          "description": "A URL pointing to a logo for this provider."
        }
      },
      "required": [
        "_id",
        "name",
        "logo"
      ],
      "description": "The institution that provides data (eg. a bank, a card issuer)."
    },
    "origin": {
      "$ref": "#/$defs/DataSourceOrigin"
    },
    "status": {
      "$ref": "#/$defs/DataSourceStatus"
    },
    "period": {
      "anyOf": [
        {
          "$ref": "#/$defs/Period"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "_id",
    "_account",
    "provider",
    "origin",
    "status",
    "period"
  ],
  "$defs": {
    "DataSourceOrigin": {
      "oneOf": [
        {
          "$ref": "#/$defs/DocumentCompleteSource"
        },
        {
          "$ref": "#/$defs/DocumentPartialSource"
        },
        {
          "$ref": "#/$defs/DatafileSource"
        }
      ],
      "description": "The origin of this data source."
    },
    "DataSourceStatus": {
      "type": "string",
      "enum": [
        "unprocessed",
        "processed",
        "duplicate"
      ],
      "description": "The status of this data source:\n\n - `processed`: This data source was successfully processed.\n\n - `unprocessed`: This data source was unable to be processed.\n\n - `duplicate`: This data source was processed, but it was identified as a duplicate."
    },
    "DatafileId": {
      "type": "string",
      "pattern": "^dat_[a-z0-9]{24,27}$"
    },
    "DatafileSource": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "datafile"
          ]
        },
        "_data_file": {
          "$ref": "#/$defs/DatafileId"
        },
        "filename": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "_data_file",
        "filename"
      ],
      "description": "A data source that represents data from an uploaded Datafile."
    },
    "DocumentCompleteSource": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "document_complete"
          ]
        },
        "_document": {
          "$ref": "#/$defs/DocumentId"
        },
        "filename": {
          "type": "string"
        },
        "page_count": {
          "type": "number"
        },
        "unreadable": {
          "type": "boolean"
        }
      },
      "required": [
        "type",
        "filename",
        "page_count"
      ],
      "description": "A data source that represents one full document."
    },
    "DocumentId": {
      "type": "string",
      "pattern": "^doc_[a-z0-9]{24,27}$"
    },
    "DocumentPartialSource": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "document_partial"
          ]
        },
        "_document": {
          "$ref": "#/$defs/DocumentId"
        },
        "filename": {
          "type": "string"
        },
        "page_start": {
          "type": "number"
        },
        "page_end": {
          "type": "number"
        }
      },
      "required": [
        "type",
        "filename",
        "page_start",
        "page_end"
      ],
      "description": "A data source that represents a range of pages within a document."
    },
    "Period": {
      "type": "object",
      "properties": {
        "start": {
          "type": "string",
          "format": "date-time"
        },
        "end": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "start",
        "end"
      ]
    },
    "ReportAccountId": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^report_acc_[a-z0-9]{24,27}$"
    },
    "ReportDataSourceId": {
      "type": "string",
      "pattern": "^src_[a-z0-9]{24,27}$"
    }
  }
}