"""
Represents a list of ordered tracks intended for continuous playback.

For example, a "/r/anime's Best OPs and EDs of 2022" playlist may contain a collection of tracks allowing the continuous playback of Best OP and ED nominations for the /r/anime Awards.
"""
type Playlist @model(class: "App\\Models\\List\\Playlist") {
    "The primary key of the resource"
    id: String! @rename(attribute: "hashid")

    "The title of the playlist"
    name: String!

    "The description of the playlist"
    description: String

    "The state of who can see the playlist"
    visibility: PlaylistVisibility!

    "The formatted string value of the visibility field"
    visibilityLocalized: String! @localized

    "The number of tracks belonging to the resource"
    tracksCount: Int! @count(relation: "tracks")

    "The existence of tracks belonging to the resource"
    tracksExists: Boolean! @aggregateCustom(column: "*", function: EXISTS, relation: "tracks")

    "The number of likes recorded for the resource"
    likesCount: Int! @aggregateCustom(column: "value", function: SUM, relation: "likeAggregate")

    "The URL for the playlist page on the website"
    siteUrl: String! @field(resolver: "App\\GraphQL\\Types\\PlaylistType@resolveSiteUrlAttribute")

    "The date that the resource was created"
    createdAt(format: String! = "Y-m-d H:i:s"): String @timestamp(attribute: "created_at")

    "The date that the resource was updated"
    updatedAt(format: String! = "Y-m-d H:i:s"): String @timestamp(attribute: "updated_at")

    first: PlaylistTrack @belongsTo

    last: PlaylistTrack @belongsTo

    user: User! @belongsTo

    tracks(
        position: Int @eq
        where: _ @whereConditions(columnsEnum: PlaylistTrackFilterableColumns, handler: "App\\GraphQL\\WhereConditions\\WhereConditionsHandler")
        sort: [PlaylistTrackSort!] @sort
    ): [PlaylistTrack!]! @hasManyCustom(type: SIMPLE)

    images(
        facet: ImageFacet @eq
        path_like: String @like(key: "path")
        where: _ @whereConditions(columnsEnum: ImageFilterableColumns, handler: "App\\GraphQL\\WhereConditions\\WhereConditionsHandler")
        sort: [ImageSort!] @sort
    ): [Image!]! @belongsToManyCustom(type: CONNECTION, edgeType: "ImageEdge")
}

extend type Query {
    "Returns a playlist resource."
    playlist(id: String! @eq(key: "hashid")): Playlist @find(model: "App\\Models\\List\\Playlist")

    "Returns a listing of playlist resources given fields."
    playlistPagination(
        name: String @eq
        name_like: String @like(key: "name")
        search: String @search
        visibility: PlaylistVisibility @eq
        where: _ @whereConditions(columnsEnum: PlaylistFilterableColumns, handler: "App\\GraphQL\\WhereConditions\\WhereConditionsHandler")
        sort: [PlaylistSort!] @sort
    ): [Playlist!]! @paginate @builder(method: "App\\GraphQL\\Builders\\List\\PlaylistPaginationBuilder")
}

extend type Mutation {
    CreatePlaylist(
        name: String!
        visibility: PlaylistVisibility!
        description: String
    ): Playlist!
    @canModel(ability: "create")
    @field(resolver: "App\\GraphQL\\Mutations\\List\\PlaylistMutation@create")

    UpdatePlaylist(
        id: String!
        name: String
        visibility: PlaylistVisibility
        description: String
    ): Playlist!
    @canFindMultiple(ability: "update", find: ["id"], models: ["App\\Models\\List\\Playlist"], columns: ["hashid"])
    @field(resolver: "App\\GraphQL\\Mutations\\List\\PlaylistMutation@update")

    DeletePlaylist(
        id: String!
    ): MessageResponse! 
    @canFindMultiple(
        ability: "delete",
        find: ["id"],
        models: ["App\\Models\\List\\Playlist"],
        columns: ["hashid"],
    )
    @field(resolver: "App\\GraphQL\\Mutations\\List\\PlaylistMutation@delete")
}