{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://chosenmasters.com/schemas/open-release-packet/v0.1.schema.json",
  "title": "Open Release Packet v0.1",
  "type": "object",
  "required": [
    "standard",
    "packet",
    "release",
    "tracks",
    "contributors",
    "rights",
    "officialRegistration",
    "openIdentifiers",
    "assets",
    "targets",
    "registry",
    "extensions",
    "portability",
    "validation"
  ],
  "additionalProperties": false,
  "properties": {
    "standard": {
      "type": "object",
      "required": ["id", "name", "version", "status"],
      "additionalProperties": false,
      "properties": {
        "id": {
          "const": "org.openreleasepacket"
        },
        "name": {
          "const": "Open Release Packet"
        },
        "version": {
          "const": "0.1.0"
        },
        "status": {
          "enum": ["draft"]
        }
      }
    },
    "packet": {
      "type": "object",
      "required": [
        "id",
        "source",
        "generatedAt",
        "schemaUrl",
        "deliveryEnabled",
        "deliveryStatus"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "generatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "schemaUrl": {
          "type": "string",
          "minLength": 1
        },
        "deliveryEnabled": {
          "const": false
        },
        "deliveryStatus": {
          "enum": ["portable_packet_only"]
        }
      }
    },
    "release": {
      "type": "object",
      "required": [
        "title",
        "openReleaseId",
        "primaryArtistName",
        "labelName",
        "releaseType",
        "releaseDate",
        "originalReleaseDate",
        "genre",
        "subgenre",
        "language",
        "identifiers",
        "copyright",
        "notes"
      ],
      "additionalProperties": false,
      "properties": {
        "title": {
          "type": "string"
        },
        "openReleaseId": {
          "type": "string"
        },
        "primaryArtistName": {
          "type": "string"
        },
        "labelName": {
          "type": "string"
        },
        "releaseType": {
          "enum": ["single", "ep", "album"]
        },
        "releaseDate": {
          "type": "string"
        },
        "originalReleaseDate": {
          "type": "string"
        },
        "genre": {
          "type": "string"
        },
        "subgenre": {
          "type": "string"
        },
        "language": {
          "type": "string"
        },
        "identifiers": {
          "type": "object",
          "required": [
            "openReleaseId",
            "upc",
            "needsUpc",
            "upcRegistrationStatus",
            "upcRegistrationProvider"
          ],
          "additionalProperties": false,
          "properties": {
            "openReleaseId": {
              "type": "string"
            },
            "upc": {
              "type": "string"
            },
            "needsUpc": {
              "type": "boolean"
            },
            "upcRegistrationStatus": {
              "type": "string"
            },
            "upcRegistrationProvider": {
              "type": "string"
            }
          }
        },
        "copyright": {
          "type": "object",
          "required": [
            "copyrightLine",
            "phonographicCopyrightLine",
            "copyrightYear",
            "phonographicCopyrightYear",
            "copyrightOwner",
            "phonographicCopyrightOwner"
          ],
          "additionalProperties": false,
          "properties": {
            "copyrightLine": {
              "type": "string"
            },
            "phonographicCopyrightLine": {
              "type": "string"
            },
            "copyrightYear": {
              "type": "string"
            },
            "phonographicCopyrightYear": {
              "type": "string"
            },
            "copyrightOwner": {
              "type": "string"
            },
            "phonographicCopyrightOwner": {
              "type": "string"
            }
          }
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "tracks": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/track"
      }
    },
    "contributors": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/contributor"
      }
    },
    "rights": {
      "type": "object",
      "required": [
        "copyrightLine",
        "phonographicCopyrightLine",
        "masterRightsOwner",
        "publishingRightsOwner",
        "copyrightOwner",
        "phonographicCopyrightOwner",
        "publicDomain",
        "clearances",
        "releaseContributors",
        "trackSplits"
      ],
      "additionalProperties": false,
      "properties": {
        "copyrightLine": {
          "type": "string"
        },
        "phonographicCopyrightLine": {
          "type": "string"
        },
        "masterRightsOwner": {
          "type": "string"
        },
        "publishingRightsOwner": {
          "type": "string"
        },
        "copyrightOwner": {
          "type": "string"
        },
        "phonographicCopyrightOwner": {
          "type": "string"
        },
        "publicDomain": {
          "type": "boolean"
        },
        "clearances": {
          "type": "object",
          "required": [
            "containsSamples",
            "sampleClearanceStatus",
            "coverSong",
            "coverSongLicenseStatus"
          ],
          "additionalProperties": false,
          "properties": {
            "containsSamples": {
              "type": "boolean"
            },
            "sampleClearanceStatus": {
              "type": "string"
            },
            "coverSong": {
              "type": "boolean"
            },
            "coverSongLicenseStatus": {
              "type": "string"
            }
          }
        },
        "releaseContributors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/contributor"
          }
        },
        "trackSplits": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["sequenceNumber", "title", "splits"],
            "additionalProperties": false,
            "properties": {
              "sequenceNumber": {
                "type": "integer",
                "minimum": 1
              },
              "title": {
                "type": "string"
              },
              "splits": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/contributor"
                }
              }
            }
          }
        }
      }
    },
    "officialRegistration": {
      "type": "object",
      "additionalProperties": true
    },
    "openIdentifiers": {
      "type": "object",
      "additionalProperties": true
    },
    "assets": {
      "type": "object",
      "required": ["coverArt", "audio"],
      "additionalProperties": false,
      "properties": {
        "coverArt": {
          "type": "object",
          "required": [
            "url",
            "embeddedDataUri",
            "sourceType",
            "requiresPermanentUri",
            "assetType"
          ],
          "additionalProperties": false,
          "properties": {
            "url": {
              "type": "string"
            },
            "embeddedDataUri": {
              "type": "string"
            },
            "sourceType": {
              "enum": ["url", "embedded_data_uri", "missing"]
            },
            "requiresPermanentUri": {
              "type": "boolean"
            },
            "assetType": {
              "const": "cover_art"
            }
          }
        },
        "audio": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "sequenceNumber",
              "title",
              "url",
              "songId",
              "assetType",
              "technical",
              "analysis",
              "stemEvidence"
            ],
            "additionalProperties": false,
            "properties": {
              "sequenceNumber": {
                "type": "integer",
                "minimum": 1
              },
              "title": {
                "type": "string"
              },
              "url": {
                "type": "string"
              },
              "songId": {
                "type": "string"
              },
              "assetType": {
                "const": "audio_master"
              },
              "technical": {
                "type": "object",
                "additionalProperties": true
              },
              "analysis": {
                "$ref": "#/$defs/audioAnalysis"
              },
              "stemEvidence": {
                "$ref": "#/$defs/stemEvidence"
              }
            }
          }
        }
      }
    },
    "targets": {
      "type": "object",
      "required": ["platforms", "availability", "deliveryIntent", "deliveryEnabled"],
      "additionalProperties": false,
      "properties": {
        "platforms": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "availability": {
          "type": "object",
          "required": ["mode", "territories", "excludedTerritories"],
          "additionalProperties": false,
          "properties": {
            "mode": {
              "type": "string"
            },
            "territories": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "excludedTerritories": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "deliveryIntent": {
          "const": "candidate_targets_only"
        },
        "deliveryEnabled": {
          "const": false
        }
      }
    },
    "registry": {
      "$ref": "#/$defs/registry"
    },
    "extensions": {
      "type": "object",
      "required": ["nft"],
      "additionalProperties": false,
      "properties": {
        "nft": {
          "type": "object",
          "required": [
            "enabled",
            "mintStatus",
            "chain",
            "contractStandard",
            "identifiers",
            "uris",
            "edition",
            "royalty",
            "unlockableContent",
            "notes",
            "boundary"
          ],
          "additionalProperties": false,
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "mintStatus": {
              "enum": ["not_planned", "planned", "minted"]
            },
            "chain": {
              "type": "string"
            },
            "contractStandard": {
              "enum": ["", "erc721", "erc1155", "metaplex", "other"]
            },
            "identifiers": {
              "type": "object",
              "required": ["contractAddress", "tokenId"],
              "additionalProperties": false,
              "properties": {
                "contractAddress": {
                  "type": "string"
                },
                "tokenId": {
                  "type": "string"
                }
              }
            },
            "uris": {
              "type": "object",
              "required": ["tokenUri", "metadataUri", "marketplaceUrl"],
              "additionalProperties": false,
              "properties": {
                "tokenUri": {
                  "type": "string"
                },
                "metadataUri": {
                  "type": "string"
                },
                "marketplaceUrl": {
                  "type": "string"
                }
              }
            },
            "edition": {
              "type": "object",
              "required": ["count"],
              "additionalProperties": false,
              "properties": {
                "count": {
                  "$ref": "#/$defs/nonNegativeIntegerOrEmpty"
                }
              }
            },
            "royalty": {
              "type": "object",
              "required": ["bps", "recipient"],
              "additionalProperties": false,
              "properties": {
                "bps": {
                  "$ref": "#/$defs/royaltyBpsOrEmpty"
                },
                "recipient": {
                  "type": "string"
                }
              }
            },
            "unlockableContent": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            },
            "boundary": {
              "type": "string"
            }
          }
        }
      }
    },
    "portability": {
      "type": "object",
      "required": ["artistOwned", "lockInPolicy", "adapterStatus"],
      "additionalProperties": false,
      "properties": {
        "artistOwned": {
          "const": true
        },
        "lockInPolicy": {
          "type": "string"
        },
        "adapterStatus": {
          "type": "object",
          "required": [
            "manualReview",
            "chosenMastersDirectSales",
            "humanReadableBundle",
            "soundExchangeIsrc",
            "gs1Upc",
            "mlcWorkRegistration",
            "ddexErn",
            "distributorApi",
            "dspDelivery"
          ],
          "additionalProperties": false,
          "properties": {
            "manualReview": {
              "type": "string"
            },
            "chosenMastersDirectSales": {
              "type": "string"
            },
            "humanReadableBundle": {
              "type": "string"
            },
            "soundExchangeIsrc": {
              "type": "string"
            },
            "gs1Upc": {
              "type": "string"
            },
            "mlcWorkRegistration": {
              "type": "string"
            },
            "ddexErn": {
              "type": "string"
            },
            "distributorApi": {
              "type": "string"
            },
            "dspDelivery": {
              "type": "string"
            }
          }
        }
      }
    },
    "validation": {
      "type": "object",
      "required": ["readyForReview", "blocking", "warnings", "summary"],
      "additionalProperties": false,
      "properties": {
        "readyForReview": {
          "type": "boolean"
        },
        "blocking": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "summary": {
          "type": "string"
        }
      }
    }
  },
  "$defs": {
    "nonNegativeIntegerOrEmpty": {
      "oneOf": [
        {
          "type": "integer",
          "minimum": 0
        },
        {
          "type": "string"
        }
      ]
    },
    "royaltyBpsOrEmpty": {
      "oneOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000
        },
        {
          "type": "string"
        }
      ]
    },
    "contributor": {
      "type": "object",
      "required": ["name", "role", "ipi", "pro", "share", "email"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string"
        },
        "role": {
          "type": "string"
        },
        "ipi": {
          "type": "string"
        },
        "pro": {
          "type": "string"
        },
        "share": {
          "oneOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            {
              "type": "string"
            }
          ]
        },
        "email": {
          "type": "string"
        }
      }
    },
    "track": {
      "type": "object",
      "required": [
        "sequenceNumber",
        "songId",
        "openRecordingId",
        "title",
        "version",
        "artistName",
        "identifiers",
        "composition",
        "explicit",
        "duration",
        "audioUrl",
        "recordingYear",
        "audioFormat",
        "sampleRate",
        "bitDepth",
        "lyricsLanguage",
        "instrumental",
        "previewStartSeconds",
        "audioAnalysis",
        "stemEvidence",
        "contributors",
        "splits",
        "notes"
      ],
      "additionalProperties": false,
      "properties": {
        "sequenceNumber": {
          "type": "integer",
          "minimum": 1
        },
        "songId": {
          "type": "string"
        },
        "openRecordingId": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "artistName": {
          "type": "string"
        },
        "identifiers": {
          "type": "object",
          "required": [
            "openRecordingId",
            "isrc",
            "needsIsrc",
            "isrcRegistrationStatus",
            "isrcRegistrationProvider",
            "iswc",
            "needsIswc"
          ],
          "additionalProperties": false,
          "properties": {
            "openRecordingId": {
              "type": "string"
            },
            "isrc": {
              "type": "string"
            },
            "needsIsrc": {
              "type": "boolean"
            },
            "isrcRegistrationStatus": {
              "type": "string"
            },
            "isrcRegistrationProvider": {
              "type": "string"
            },
            "iswc": {
              "type": "string"
            },
            "needsIswc": {
              "type": "boolean"
            }
          }
        },
        "composition": {
          "type": "object",
          "required": [
            "title",
            "registrationStatus",
            "mechanicalRegistrationStatus"
          ],
          "additionalProperties": false,
          "properties": {
            "title": {
              "type": "string"
            },
            "registrationStatus": {
              "type": "string"
            },
            "mechanicalRegistrationStatus": {
              "type": "string"
            }
          }
        },
        "explicit": {
          "type": "boolean"
        },
        "duration": {
          "type": "string"
        },
        "audioUrl": {
          "type": "string"
        },
        "recordingYear": {
          "type": "string"
        },
        "audioFormat": {
          "type": "string"
        },
        "sampleRate": {
          "type": "string"
        },
        "bitDepth": {
          "type": "string"
        },
        "lyricsLanguage": {
          "type": "string"
        },
        "instrumental": {
          "type": "boolean"
        },
        "previewStartSeconds": {
          "oneOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "string"
            }
          ]
        },
        "audioAnalysis": {
          "$ref": "#/$defs/audioAnalysis"
        },
        "stemEvidence": {
          "$ref": "#/$defs/stemEvidence"
        },
        "contributors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/contributor"
          }
        },
        "splits": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/contributor"
          }
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "audioAnalysis": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "status",
        "algorithm",
        "sourceSha256",
        "fingerprintHash",
        "waveformPeaks",
        "peakCount",
        "durationSeconds",
        "sampleRate",
        "channels",
        "analyzedAt",
        "duplicateCheck"
      ],
      "properties": {
        "status": {
          "type": "string"
        },
        "algorithm": {
          "type": "string"
        },
        "sourceSha256": {
          "type": "string"
        },
        "fingerprintHash": {
          "type": "string"
        },
        "waveformPeaks": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "peakCount": {
          "type": "integer",
          "minimum": 0
        },
        "durationSeconds": {
          "oneOf": [{ "type": "number" }, { "type": "string" }]
        },
        "sampleRate": {
          "oneOf": [{ "type": "number" }, { "type": "string" }]
        },
        "channels": {
          "oneOf": [{ "type": "number" }, { "type": "string" }]
        },
        "analyzedAt": {
          "type": "string"
        },
        "duplicateCheck": {
          "type": "object",
          "additionalProperties": true,
          "required": [
            "status",
            "checkedAt",
            "candidateCount",
            "candidates",
            "reviewStatus",
            "reviewedAt",
            "reviewedBy",
            "reviewNotes"
          ],
          "properties": {
            "status": {
              "type": "string"
            },
            "checkedAt": {
              "type": "string"
            },
            "candidateCount": {
              "type": "integer",
              "minimum": 0
            },
            "candidates": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true,
                "properties": {
                  "songId": {
                    "type": "string"
                  },
                  "releaseId": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "artistName": {
                    "type": "string"
                  },
                  "matchType": {
                    "type": "string"
                  },
                  "confidence": {
                    "type": "string"
                  },
                  "score": {
                    "type": "number"
                  },
                  "distance": {
                    "oneOf": [{ "type": "number" }, { "type": "string" }]
                  },
                  "durationScore": {
                    "oneOf": [{ "type": "number" }, { "type": "string" }]
                  },
                  "reviewStatus": {
                    "type": "string"
                  },
                  "adminNotes": {
                    "type": "string"
                  }
                }
              }
            },
            "reviewStatus": {
              "type": "string"
            },
            "reviewedAt": {
              "type": "string"
            },
            "reviewedBy": {
              "type": "string"
            },
            "reviewNotes": {
              "type": "string"
            }
          }
        }
      }
    },
    "stemEvidence": {
      "type": "object",
      "required": [
        "enabled",
        "status",
        "archiveUrl",
        "sourceSha256",
        "storageKey",
        "fileName",
        "fileSize",
        "contentType",
        "uploadedAt",
        "notes"
      ],
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "status": {
          "type": "string"
        },
        "archiveUrl": {
          "type": "string"
        },
        "sourceSha256": {
          "type": "string"
        },
        "storageKey": {
          "type": "string"
        },
        "fileName": {
          "type": "string"
        },
        "fileSize": {
          "oneOf": [{ "type": "number" }, { "type": "string" }]
        },
        "contentType": {
          "type": "string"
        },
        "uploadedAt": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "registry": {
      "type": "object",
      "required": [
        "visibility",
        "status",
        "slug",
        "publishedAt",
        "searchable",
        "publicNotes",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "visibility": {
          "enum": ["private", "unlisted", "public"]
        },
        "status": {
          "type": "string"
        },
        "slug": {
          "type": "string"
        },
        "publishedAt": {
          "type": "string"
        },
        "searchable": {
          "type": "boolean"
        },
        "publicNotes": {
          "type": "string"
        },
        "boundary": {
          "type": "string"
        }
      }
    }
  }
}
