openapi: 3.0.3
info:
  title: Open Playlist API
  description: |
    A universal, open, and interoperable playlist API specification.
    Enables seamless migration, local playlist-file import, and portable export of
    playlists and explicit music-library entities across Spotify, Tidal, YouTube
    Music, Deezer, Apple Music, and beyond.
  version: 0.2.0
  license:
    name: MIT

servers:
  - url: https://api.example.com/v1
    description: Example server (replace with your own)

paths:
  /open-playlists/{userId}:
    get:
      summary: List user playlists
      description: Returns all playlists owned by the specified user in Open Playlist format.
      operationId: listUserPlaylists
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The unique identifier of the user.
      responses:
        "200":
          description: A list of playlists.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Playlist"
        "404":
          description: User not found.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /open-playlists/{playlistId}:
    get:
      summary: Get a playlist
      description: Retrieves a single playlist by its unique identifier.
      operationId: getPlaylist
      parameters:
        - name: playlistId
          in: path
          required: true
          schema:
            type: string
          description: The unique identifier of the playlist.
      responses:
        "200":
          description: The requested playlist.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Playlist"
        "404":
          description: Playlist not found.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /open-playlists/import:
    post:
      summary: Import a playlist
      description: |
        Imports a playlist from a provider-specific format into the universal
        Open Playlist format. The request body must include the source provider
        and the provider-specific playlist data.
      operationId: importPlaylist
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ImportRequest"
      responses:
        "201":
          description: Playlist imported successfully.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Playlist"
        "400":
          description: Invalid import data.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /open-playlists/export:
    post:
      summary: Export a playlist
      description: |
        Exports a playlist from the universal Open Playlist format to a
        target provider. The request body must include the playlist ID and
        the target provider name.
      operationId: exportPlaylist
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ExportRequest"
      responses:
        "200":
          description: Playlist exported successfully.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ExportResponse"
        "400":
          description: Invalid export request.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /api/imports/preview:
    post:
      summary: Validate a local playlist file
      description: |
        Streams one supported playlist file into a bounded local parser and
        returns an expiring normalized preview. The raw file is closed after
        parsing and is never sent to an external service.
      operationId: previewLocalPlaylistFile
      parameters:
        - name: filename
          in: query
          required: true
          schema:
            type: string
            maxLength: 255
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
      responses:
        "201":
          description: Parsed playlist preview.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LocalImportPreview"
        "413":
          description: Configured upload-size limit exceeded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImportError"
        "422":
          description: Unsupported, malformed, or item-limit-exceeding input.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImportError"

  /api/imports/{importId}:
    parameters:
      - name: importId
        in: path
        required: true
        schema:
          type: string
          format: uuid
    get:
      summary: Get an unexpired local import preview
      operationId: getLocalPlaylistImport
      responses:
        "200":
          description: Current normalized preview.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LocalImportPreview"
        "404":
          description: Import not found for the current user.
        "410":
          description: Import expired and must be uploaded again.
    delete:
      summary: Discard an unused local import preview
      operationId: discardLocalPlaylistImport
      responses:
        "204":
          description: Preview discarded.
        "404":
          description: Import not found for the current user.
        "409":
          description: Import is already queued for migration.

  /organizer/preflight:
    post:
      summary: Preview playlist organizer operations
      operationId: preflightOrganizer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrganizerRequest"
      responses:
        "200":
          description: Exact provider operations, recovery implications, and confirmation.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrganizerPreflight"
        "400":
          description: Invalid or stale organizer selection.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /organizer/playlists:
    get:
      summary: List playlists with organizer capabilities
      operationId: listOrganizerPlaylists
      parameters:
        - name: provider
          in: query
          required: true
          schema:
            type: string
        - name: account_id
          in: query
          required: true
          schema:
            type: string
        - name: refresh
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        "200":
          description: Provider playlists annotated with ownership and supported actions.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/OrganizerPlaylistView"
        "400":
          description: Provider or account request failed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /open-playlists/export/file:
    post:
      summary: Export playlists to portable local files
      description: |
        Serializes one or more provider playlists through the universal Open
        Playlist model. A single playlist is returned directly. Multiple
        playlists are returned as a ZIP64 archive with a versioned manifest.
      operationId: exportPortablePlaylistFiles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PortableExportRequest"
      responses:
        "200":
          description: Portable playlist file or ZIP archive.
          headers:
            Content-Disposition:
              schema:
                type: string
            X-Open-Playlist-Schema-Version:
              schema:
                type: integer
                enum: [1]
            X-Open-Playlist-Warning-Count:
              schema:
                type: integer
                minimum: 0
          content:
            text/csv:
              schema:
                type: string
                format: binary
            text/plain:
              schema:
                type: string
                format: binary
            application/vnd.apple.mpegurl:
              schema:
                type: string
                format: binary
            application/xspf+xml:
              schema:
                type: string
                format: binary
            application/vnd.open-playlist+json:
              schema:
                type: string
                format: binary
            application/zip:
              schema:
                type: string
                format: binary
        "400":
          description: Invalid selection or export limit exceeded.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /organizer/duplicates:
    post:
      summary: Find review-only duplicate playlist candidates
      operationId: analyzeOrganizerDuplicates
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrganizerRequest"
      responses:
        "200":
          description: Explainable candidates. No action is created or selected.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/DuplicateCandidate"

  /organizer/jobs:
    get:
      summary: List recent organizer jobs
      operationId: listOrganizerJobs
      responses:
        "200":
          description: Recent organizer audit reports.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/OrganizerJob"
    post:
      summary: Start a durable organizer job
      operationId: createOrganizerJob
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OrganizerRequest"
      responses:
        "200":
          description: Queued organizer job.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrganizerJob"
        "409":
          description: Unsupported selections or exact typed confirmation required.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrganizerPreflight"

  /organizer/jobs/{jobId}:
    get:
      summary: Get one organizer audit report
      operationId: getOrganizerJob
      parameters:
        - name: jobId
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Organizer job and per-playlist results.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrganizerJob"

  /organizer/jobs/{jobId}/retry:
    post:
      summary: Retry failed organizer items only
      operationId: retryOrganizerJob
      parameters:
        - name: jobId
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Requeued job. Successful items remain complete.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrganizerJob"

components:
  schemas:
    Playlist:
      type: object
      required:
        - name
        - tracks
      properties:
        id:
          type: string
          nullable: true
          description: Provider-agnostic unique playlist identifier.
          example: "550e8400-e29b-41d4-a716-446655440000"
        name:
          type: string
          description: The name of the playlist.
          example: "Summer Vibes 2026"
        description:
          type: string
          nullable: true
          description: A short description of the playlist.
          example: "Upbeat tracks for sunny days."
        photo:
          type: string
          format: uri
          nullable: true
          description: URI to the playlist cover image.
          example: "https://images.example.com/playlists/summer-vibes.jpg"
        tracks:
          type: array
          items:
            $ref: "#/components/schemas/Track"
          description: Ordered list of tracks in the playlist.
        owner_id:
          type: string
          nullable: true
          description: The unique identifier of the playlist owner.
          example: "user-42"
        owner_name:
          type: string
          description: Display name for the playlist owner when exposed by the provider.
        is_owned:
          type: boolean
          nullable: true
          description: Whether the connected account owns the playlist.
        is_followed:
          type: boolean
          nullable: true
          description: Whether the playlist is followed rather than owned.
        collaborative:
          type: boolean
          nullable: true
          description: Whether the connected account can collaborate on the playlist.
        created_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when the playlist was created.
          example: "2026-01-15T10:30:00Z"
        updated_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when the playlist was last updated.
          example: "2026-02-01T14:00:00Z"
        snapshot_id:
          type: string
          nullable: true
          description: Provider snapshot/version identifier when available.
        kind:
          type: string
          enum: [standard, liked_tracks]
          default: standard
          description: Standard playlist or provider-native liked/saved collection.

    Track:
      type: object
      required:
        - title
        - artist
      properties:
        id:
          type: string
          nullable: true
          description: Universal unique track identifier.
          example: "6fa459ea-ee8a-3ca4-894e-db77e160355e"
        title:
          type: string
          description: The title of the track.
          example: "Blinding Lights"
        artist:
          type: string
          description: Primary artist name.
          example: "The Weeknd"
        album:
          type: string
          nullable: true
          description: Album name.
          example: "After Hours"
        duration_s:
          type: integer
          nullable: true
          description: Track duration in seconds.
          example: 200
        release_date:
          type: string
          format: date
          nullable: true
          description: Full release (publication) date of the track, when known.
          example: "2020-03-20"
        release_year:
          type: integer
          nullable: true
          description: Year of publication. Useful when only the year is known.
          example: 2020
        genre:
          type: string
          nullable: true
          description: Primary genre of the track.
          example: "Synth-pop"
        track_number:
          type: integer
          nullable: true
          description: Position of the track within its album or disc.
          example: 9
        disc_number:
          type: integer
          nullable: true
          description: Disc number for multi-disc albums.
          example: 1
        explicit:
          type: boolean
          nullable: true
          description: Indicates whether the track contains explicit content.
          example: false
        composer:
          type: string
          nullable: true
          description: Composer or songwriter credited for the track.
          example: "Abel Tesfaye"
        credits:
          type: array
          items:
            $ref: "#/components/schemas/Credit"
          description: |
            Detailed list of people and entities credited on the track, such as
            featured artists, producers, composers, lyricists, mixing engineers,
            and more. Complements the simple `artist` and `composer` fields by
            capturing the full set of contributors and their roles.
          example:
            - role: "featured_artist"
              name: "Daft Punk"
            - role: "producer"
              name: "Max Martin"
            - role: "lyricist"
              name: "Savan Kotecha"
        label:
          type: string
          nullable: true
          description: Record label that published the track.
          example: "XO / Republic Records"
        isrc:
          type: string
          nullable: true
          description: International Standard Recording Code.
          example: "USUG12000497"
        artwork_uri:
          type: string
          format: uri
          nullable: true
          description: URI to track or album artwork.
          example: "https://images.example.com/tracks/blinding-lights.jpg"
        provider_uris:
          type: object
          additionalProperties:
            type: string
          description: Map of provider names to their corresponding track URIs.
          example:
            spotify: "spotify:track:0VjIjW4GlUZAMYd2vXMi3b"
            apple_music: "https://music.apple.com/us/album/blinding-lights/1499378108?i=1499378612"
            youtube_music: "https://music.youtube.com/watch?v=4NRXx6U8ABQ"
            tidal: "https://tidal.com/browse/track/123456789"
            deezer: "https://www.deezer.com/track/908604462"
        metadata:
          type: object
          additionalProperties: true
          description: Extensible key-value metadata for platform-specific fields.
          example:
            genre: "Synth-pop"
            bpm: 171
        migration_status:
          type: string
          nullable: true
          description: Optional engine migration annotation.
        migrated_target_playlist_id:
          type: string
          nullable: true
          description: Optional target playlist annotation.
        migrated_target_uri:
          type: string
          nullable: true
          description: Optional target item URI annotation.
        position:
          type: integer
          nullable: true
          description: Provider source position when available.
        media_type:
          type: string
          enum: [track, episode, video, local_file, unknown]
          default: track
        is_local:
          type: boolean
          default: false
        source_item_id:
          type: string
          nullable: true
          description: Provider occurrence or playlist-item identifier.
        added_at:
          type: string
          format: date-time
          nullable: true
          description: Date the item was added to the playlist.
        unsupported_reason:
          type: string
          nullable: true
          description: Reason the item cannot be migrated or played when known.

    Album:
      type: object
      required:
        - title
        - artists
        - provider_uris
      properties:
        id:
          type: string
          nullable: true
          description: Stable provider album identifier when available.
        title:
          type: string
          description: Album title.
        artists:
          type: array
          items:
            type: string
          description: Ordered album artist names.
        upc:
          type: string
          nullable: true
          description: UPC or provider-equivalent barcode used as strong match evidence.
        release_date:
          type: string
          format: date
          nullable: true
        release_year:
          type: integer
          nullable: true
          description: Release year when the provider exposes only partial date precision.
        artwork_uri:
          type: string
          format: uri
          nullable: true
        provider_uris:
          type: object
          additionalProperties:
            type: string
          description: Provider album URIs keyed by provider name.
        metadata:
          type: object
          additionalProperties: true
        source_item_id:
          type: string
          nullable: true
          description: Stable source-library item identifier.
        added_at:
          type: string
          format: date-time
          nullable: true

    Artist:
      type: object
      required:
        - name
        - provider_uris
      properties:
        id:
          type: string
          nullable: true
          description: Stable provider artist identifier when available.
        name:
          type: string
        artwork_uri:
          type: string
          format: uri
          nullable: true
        provider_uris:
          type: object
          additionalProperties:
            type: string
          description: Provider artist URIs keyed by provider name.
        metadata:
          type: object
          additionalProperties: true
        source_item_id:
          type: string
          nullable: true
          description: Stable source-library item identifier.
        added_at:
          type: string
          format: date-time
          nullable: true
          description: Date the artist was added or favorited when available.

    Credit:
      type: object
      required:
        - role
        - name
      properties:
        role:
          type: string
          description: |
            The role this contributor played on the track. Common values include
            `featured_artist`, `producer`, `composer`, `lyricist`, `songwriter`,
            `arranger`, `mixing_engineer`, `mastering_engineer`, and `performer`.
            The list is intentionally open-ended so providers can express any role.
          example: "producer"
        name:
          type: string
          description: Name of the person or entity credited.
          example: "Max Martin"
        instrument:
          type: string
          nullable: true
          description: |
            Optional instrument or specialization for performer credits.
          example: "guitar"
        uri:
          type: string
          format: uri
          nullable: true
          description: Optional URI identifying the contributor (e.g. an artist page).
          example: "https://music.example.com/artist/max-martin"

    PortableExportFormat:
      type: string
      enum: [csv, txt, m3u8, xspf, json]

    PlaylistSelection:
      type: object
      required:
        - playlist_ids
      properties:
        playlist_ids:
          type: array
          minItems: 1
          items:
            type: string
          description: Playlist identifiers in output order.
        tracks:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          default: {}
          description: Optional selected track/item identifiers by playlist ID.

    PortableExportRequest:
      type: object
      required:
        - source_provider
        - source_account_id
        - format
        - selection
      properties:
        source_provider:
          type: string
          example: spotify
        source_account_id:
          type: string
        format:
          $ref: "#/components/schemas/PortableExportFormat"
        selection:
          $ref: "#/components/schemas/PlaylistSelection"

    ExportWarning:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
        playlist_id:
          type: string
          nullable: true

    OpenPlaylistBundle:
      type: object
      required:
        - $schema
        - schema_version
        - source_provider
        - playlists
        - warnings
      properties:
        $schema:
          type: string
          enum:
            - https://openplaylistengine.dev/schemas/export/open-playlist-bundle-v1.json
        schema_version:
          type: integer
          enum: [1]
        source_provider:
          type: string
        playlists:
          type: array
          items:
            $ref: "#/components/schemas/Playlist"
        warnings:
          type: array
          items:
            $ref: "#/components/schemas/ExportWarning"

    ExportManifestEntry:
      type: object
      required:
        - playlist_id
        - playlist_name
        - filename
        - status
        - track_count
        - warning_codes
      properties:
        playlist_id:
          type: string
        playlist_name:
          type: string
        filename:
          type: string
        status:
          type: string
          enum: [ok, warning, error]
        track_count:
          type: integer
          minimum: 0
        warning_codes:
          type: array
          items:
            type: string

    ExportManifest:
      type: object
      required:
        - $schema
        - schema_version
        - format
        - source_provider
        - playlist_count
        - entries
        - warnings
      properties:
        $schema:
          type: string
          enum:
            - https://openplaylistengine.dev/schemas/export/open-playlist-export-manifest-v1.json
        schema_version:
          type: integer
          enum: [1]
        format:
          $ref: "#/components/schemas/PortableExportFormat"
        source_provider:
          type: string
        playlist_count:
          type: integer
          minimum: 1
        entries:
          type: array
          items:
            $ref: "#/components/schemas/ExportManifestEntry"
        warnings:
          type: array
          items:
            $ref: "#/components/schemas/ExportWarning"

    ImportRequest:
      type: object
      required:
        - source_provider
        - provider_data
      properties:
        source_provider:
          type: string
          description: The name of the provider to import from.
          example: "spotify"
        provider_data:
          type: object
          additionalProperties: true
          description: Provider-specific playlist data. The structure depends on the source provider.

    ExportRequest:
      type: object
      required:
        - playlist_id
        - target_provider
      properties:
        playlist_id:
          type: string
          format: uuid
          description: The ID of the Open Playlist to export.
          example: "550e8400-e29b-41d4-a716-446655440000"
        target_provider:
          type: string
          description: The name of the provider to export to.
          example: "apple_music"

    ExportResponse:
      type: object
      properties:
        provider:
          type: string
          description: The provider the playlist was exported to.
          example: "apple_music"
        provider_playlist_url:
          type: string
          format: uri
          description: URL of the exported playlist on the target provider.
          example: "https://music.apple.com/us/playlist/summer-vibes-2026/pl.abc123"
        status:
          type: string
          description: Status of the export operation.
          example: "success"
        tracks_matched:
          type: integer
          description: Number of tracks successfully matched on the target provider.
          example: 18
        tracks_unmatched:
          type: integer
          description: Number of tracks that could not be matched on the target provider.
          example: 2

    ImportIssue:
      type: object
      required:
        - severity
        - code
        - message
      properties:
        severity:
          type: string
          enum: [warning, error]
        code:
          type: string
        message:
          type: string
        line_or_item:
          oneOf:
            - type: integer
            - type: string
          nullable: true
        playlist_name:
          type: string
          nullable: true
        raw_excerpt:
          type: string
          nullable: true

    ImportLimits:
      type: object
      required:
        - max_upload_bytes
        - max_playlists
        - max_tracks
        - max_issues
        - spool_memory_bytes
      properties:
        max_upload_bytes:
          type: integer
        max_playlists:
          type: integer
        max_tracks:
          type: integer
        max_issues:
          type: integer
        spool_memory_bytes:
          type: integer

    LocalImportPreview:
      type: object
      required:
        - id
        - filename
        - detected_format
        - file_size
        - status
        - expires_at
        - playlists
        - issues
        - playlist_count
        - track_count
        - duplicate_count
        - malformed_count
        - unsupported_count
        - limits
      properties:
        id:
          type: string
          format: uuid
        filename:
          type: string
        detected_format:
          type: string
          enum: [txt, csv, m3u, m3u8, pls, wpl, xspf, xml, json]
        encoding:
          type: string
          nullable: true
        file_size:
          type: integer
        status:
          type: string
          enum: [ready, queued, failed]
        expires_at:
          type: string
          format: date-time
        playlists:
          type: array
          items:
            $ref: "#/components/schemas/Playlist"
        issues:
          type: array
          items:
            $ref: "#/components/schemas/ImportIssue"
        playlist_count:
          type: integer
        track_count:
          type: integer
        duplicate_count:
          type: integer
        malformed_count:
          type: integer
        unsupported_count:
          type: integer
        limits:
          $ref: "#/components/schemas/ImportLimits"

    ImportError:
      type: object
      properties:
        detail:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            format:
              type: string
              nullable: true

    OrganizerIntent:
      type: string
      enum: [remove, delete, remove_tracks]

    OrganizerPlaylistRef:
      type: object
      required: [id, name, kind]
      properties:
        id:
          type: string
        name:
          type: string
        track_count:
          type: integer
          nullable: true
        owner_id:
          type: string
          nullable: true
        owner_name:
          type: string
          nullable: true
        is_owned:
          type: boolean
          nullable: true
        is_followed:
          type: boolean
          nullable: true
        collaborative:
          type: boolean
          nullable: true
        snapshot_id:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
          nullable: true
        updated_at:
          type: string
          format: date-time
          nullable: true
        kind:
          type: string
          enum: [standard, liked_tracks]

    OrganizerPlaylistView:
      type: object
      required:
        - playlist
        - ownership
        - available_intents
        - requires_ownership_check
        - notes
      properties:
        playlist:
          $ref: "#/components/schemas/OrganizerPlaylistRef"
        ownership:
          type: string
          enum: [owned, collaborative, followed, unknown]
        available_intents:
          type: array
          items:
            $ref: "#/components/schemas/OrganizerIntent"
        requires_ownership_check:
          type: boolean
        notes:
          type: array
          items:
            type: string

    OrganizerTrackSelection:
      type: object
      required: [position]
      properties:
        position:
          type: integer
          minimum: 0
        source_item_id:
          type: string
          nullable: true

    OrganizerSelection:
      type: object
      properties:
        playlist_actions:
          type: array
          items:
            type: object
            required: [playlist_id, intent]
            properties:
              playlist_id:
                type: string
              intent:
                $ref: "#/components/schemas/OrganizerIntent"
        track_removals:
          type: array
          items:
            type: object
            required: [playlist_id, tracks]
            properties:
              playlist_id:
                type: string
              tracks:
                type: array
                items:
                  $ref: "#/components/schemas/OrganizerTrackSelection"

    OrganizerRequest:
      type: object
      required: [provider, account_id, selection]
      properties:
        provider:
          type: string
        account_id:
          type: string
        selection:
          $ref: "#/components/schemas/OrganizerSelection"
        confirmation:
          type: string
          nullable: true
          description: Exact phrase returned by preflight for irreversible operations.

    OrganizerPreflight:
      type: object
      required:
        - code
        - groups
        - unsupported
        - confirmation_required
        - total_playlists
        - total_tracks
      properties:
        code:
          type: string
          enum: [organizer_preflight, organizer_confirmation_required]
        groups:
          type: array
          items:
            $ref: "#/components/schemas/OrganizerPreflightGroup"
        unsupported:
          type: array
          items:
            $ref: "#/components/schemas/OrganizerUnsupported"
        confirmation_required:
          type: boolean
        confirmation_phrase:
          type: string
          nullable: true
        total_playlists:
          type: integer
        total_tracks:
          type: integer

    OrganizerPreflightGroup:
      type: object
      required: [action, label, destructive, recovery, items]
      properties:
        action:
          type: string
          enum: [unfollow_playlist, delete_playlist, remove_tracks]
        label:
          type: string
        destructive:
          type: boolean
        recovery:
          type: string
        items:
          type: array
          items:
            type: object
            required:
              - playlist_id
              - playlist_name
              - action
              - destructive
              - ownership
              - selected_track_count
              - recovery
            properties:
              playlist_id:
                type: string
              playlist_name:
                type: string
              action:
                type: string
              destructive:
                type: boolean
              ownership:
                type: string
              collaborative:
                type: boolean
                nullable: true
              selected_track_count:
                type: integer
              recovery:
                type: string

    OrganizerUnsupported:
      type: object
      required: [playlist_id, playlist_name, intent, reason]
      properties:
        playlist_id:
          type: string
        playlist_name:
          type: string
        intent:
          $ref: "#/components/schemas/OrganizerIntent"
        reason:
          type: string

    OrganizerJob:
      type: object
      required:
        - id
        - provider
        - account_id
        - status
        - total
        - done
        - failed
        - items
      properties:
        id:
          type: string
        provider:
          type: string
        account_id:
          type: string
        status:
          type: string
          enum: [pending, running, done, partial, failed]
        total:
          type: integer
        done:
          type: integer
        failed:
          type: integer
        error:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
          nullable: true
        updated_at:
          type: string
          format: date-time
          nullable: true
        items:
          type: array
          items:
            $ref: "#/components/schemas/OrganizerItem"

    OrganizerItem:
      type: object
      required:
        - id
        - playlist_id
        - playlist_name
        - action
        - destructive
        - ownership
        - status
        - attempts
        - retryable
      properties:
        id:
          type: string
        playlist_id:
          type: string
        playlist_name:
          type: string
        action:
          type: string
          enum: [unfollow_playlist, delete_playlist, remove_tracks]
        destructive:
          type: boolean
        ownership:
          type: string
        collaborative:
          type: boolean
          nullable: true
        status:
          type: string
        attempts:
          type: integer
        retryable:
          type: boolean
        error:
          type: string
          nullable: true
        request_payload:
          type: object
          additionalProperties: true
        result_payload:
          type: object
          additionalProperties: true

    DuplicateCandidate:
      type: object
      required:
        - playlist_ids
        - playlist_names
        - normalized_name
        - overlap_count
        - overlap_ratio
        - reasons
      properties:
        playlist_ids:
          type: array
          minItems: 2
          maxItems: 2
          items:
            type: string
        playlist_names:
          type: array
          minItems: 2
          maxItems: 2
          items:
            type: string
        normalized_name:
          type: string
        overlap_count:
          type: integer
        overlap_ratio:
          type: number
          format: float
        reasons:
          type: array
          items:
            type: string

    Error:
      type: object
      properties:
        code:
          type: integer
          description: HTTP status code.
          example: 404
        message:
          type: string
          description: Human-readable error message.
          example: "Playlist not found."
