query trackers($cursor: Cursor) {
    trackers(cursor: $cursor) {
        ...trackers
    }
}

query trackersByUser($username: String!, $cursor: Cursor) {
    user(username: $username) {
        trackers(cursor: $cursor) {
            ...trackers
        }
    }
}

fragment trackers on TrackerCursor {
    results {
        name
        description
        visibility
    }
    cursor
}

query trackerIDByName($name: String!) {
    me {
        tracker(name: $name) {
            id
        }
    }
}

query trackerIDByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            id
        }
    }
}

query tickets($name: String!) {
    me {
        tracker(name: $name) {
            tickets {
                ...tickets
            }
        }
    }
}

query ticketsByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            tickets {
                ...tickets
            }
        }
    }
}

fragment tickets on TicketCursor {
    results {
        id
        subject
        status
        resolution
        created
        submitter {
            canonicalName
        }
        labels {
            name
            backgroundColor
            foregroundColor
        }
    }
}

query labels($name: String!) {
    me {
        tracker(name: $name) {
            labels {
                ...labels
            }
        }
    }
}

query labelsByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            labels {
                ...labels
            }
        }
    }
}

fragment labels on LabelCursor {
    results {
        name
        backgroundColor
        foregroundColor
    }
}

query aclByTrackerName($name: String!) {
    me {
        tracker(name: $name) {
            defaultACL {
                browse
                submit
                comment
                edit
                triage
            }
            acls {
                results {
                    id
                    created
                    entity {
                        canonicalName
                    }
                    browse
                    submit
                    comment
                    edit
                    triage
                }
            }
        }
    }
}

query userIDByName($username: String!) {
    user(username: $username) {
        id
    }
}

query assignees($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
        }
    }
}

query assigneesByUser($username: String!, $name: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
        }
    }
}

query completeTicketId($name: String!, $subscription: Boolean!) {
    me {
        tracker(name: $name) {
            ...completeTicket
        }
    }
}

query completeTicketIdByUser(
    $username: String!
    $name: String!
    $subscription: Boolean!
) {
    user(username: $username) {
        tracker(name: $name) {
            ...completeTicket
        }
    }
}

fragment completeTicket on Tracker {
    tickets {
        results {
            id
            subject
            ... on Ticket @include(if: $subscription) {
                subscription {
                    id
                }
            }
        }
    }
}

query completeTicketAssign($name: String!, $id: Int!) {
    me {
        canonicalName
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
            tickets {
                results {
                    assignees {
                        canonicalName
                    }
                }
            }
        }
    }
}

query completeTicketAssignByUser(
    $username: String!
    $name: String!
    $id: Int!
) {
    me {
        canonicalName
    }

    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
            tickets {
                results {
                    assignees {
                        canonicalName
                    }
                }
            }
        }
    }
}

query trackerNames {
    trackers {
        results {
            name
        }
    }
}

query ticketWebhooks($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                ...ticketWebhooks
            }
        }
    }
}

query ticketWebhooksByUser($username: String!, $name: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                ...ticketWebhooks
            }
        }
    }
}

fragment ticketWebhooks on Ticket {
    webhooks {
        results {
            id
            url
        }
    }
}

query userWebhooks {
    userWebhooks {
        results {
            id
            url
        }
    }
}

query trackerWebhooks($name: String!) {
    me {
        tracker(name: $name) {
            ...trackerWebhooks
        }
    }
}

query trackerWebhooksByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            ...trackerWebhooks
        }
    }
}

fragment trackerWebhooks on Tracker {
    webhooks {
        results {
            id
            url
        }
    }
}

query ticketByName($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                ...ticket
            }
        }
    }
}

query ticketByUser($username: String!, $tracker: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $tracker) {
            ticket(id: $id) {
                ...ticket
            }
        }
    }
}

fragment ticket on Ticket {
    created
    updated
    submitter {
        canonicalName
    }
    subject
    body
    status
    resolution
    labels {
        name
        backgroundColor
        foregroundColor
    }
    assignees {
        canonicalName
    }
}

query labelIDByName($trackerName: String!, $labelName: String!) {
    me {
        tracker(name: $trackerName) {
            label(name: $labelName) {
                id
            }
        }
    }
}

query labelIDByUser(
    $username: String!
    $trackerName: String!
    $labelName: String!
) {
    user(username: $username) {
        tracker(name: $trackerName) {
            label(name: $labelName) {
                id
            }
        }
    }
}

query completeLabel($name: String!) {
    me {
        tracker(name: $name) {
            labels {
                results {
                    name
                }
            }
        }
    }
}

query completeLabelByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            labels {
                results {
                    name
                }
            }
        }
    }
}

mutation deleteTracker($id: Int!) {
    deleteTracker(id: $id) {
        name
    }
}

mutation submitComment(
    $trackerId: Int!
    $ticketId: Int!
    $input: SubmitCommentInput!
) {
    submitComment(trackerId: $trackerId, ticketId: $ticketId, input: $input) {
        ticket {
            subject
        }
    }
}

mutation updateTicketStatus(
    $trackerId: Int!
    $ticketId: Int!
    $input: UpdateStatusInput!
) {
    updateTicketStatus(
        trackerId: $trackerId
        ticketId: $ticketId
        input: $input
    ) {
        ticket {
            subject
        }
    }
}

mutation deleteLabel($id: Int!) {
    deleteLabel(id: $id) {
        name
    }
}

mutation createLabel(
    $trackerId: Int!
    $name: String!
    $foregroundColor: String!
    $backgroundColor: String!
) {
    createLabel(
        trackerId: $trackerId
        name: $name
        foregroundColor: $foregroundColor
        backgroundColor: $backgroundColor
    ) {
        name
        backgroundColor
        foregroundColor
    }
}

mutation deleteACL($id: Int!) {
    deleteACL(id: $id) {
        tracker {
            name
        }
        entity {
            canonicalName
        }
    }
}

mutation trackerSubscribe($trackerId: Int!) {
    trackerSubscribe(trackerId: $trackerId) {
        tracker {
            name
            owner {
                canonicalName
            }
        }
    }
}

mutation trackerUnsubscribe($trackerId: Int!) {
    # TODO: Wait for API to implement "tickets"
    trackerUnsubscribe(trackerId: $trackerId, tickets: false) {
        tracker {
            name
            owner {
                canonicalName
            }
        }
    }
}

mutation ticketSubscribe($trackerId: Int!, $ticketId: Int!) {
    ticketSubscribe(trackerId: $trackerId, ticketId: $ticketId) {
        ticket {
            id
        }
    }
}

mutation ticketUnsubscribe($trackerId: Int!, $ticketId: Int!) {
    ticketUnsubscribe(trackerId: $trackerId, ticketId: $ticketId) {
        ticket {
            id
        }
    }
}

mutation assignUser($trackerId: Int!, $ticketId: Int!, $userId: Int!) {
    assignUser(trackerId: $trackerId, ticketId: $ticketId, userId: $userId) {
        ticket {
            subject
        }
    }
}

mutation unassignUser($trackerId: Int!, $ticketId: Int!, $userId: Int!) {
    unassignUser(trackerId: $trackerId, ticketId: $ticketId, userId: $userId) {
        ticket {
            subject
        }
    }
}

mutation createTracker(
    $name: String!
    $description: String
    $visibility: Visibility!
) {
    createTracker(
        name: $name
        description: $description
        visibility: $visibility
    ) {
        name
    }
}

mutation deleteTicket($trackerId: Int!, $ticketId: Int!) {
    deleteTicket(trackerId: $trackerId, ticketId: $ticketId) {
        subject
    }
}

mutation createTicketWebhook(
    $trackerId: Int!
    $ticketId: Int!
    $config: TicketWebhookInput!
) {
    createTicketWebhook(
        trackerId: $trackerId
        ticketId: $ticketId
        config: $config
    ) {
        id
    }
}

mutation deleteTicketWebhook($id: Int!) {
    deleteTicketWebhook(id: $id) {
        id
    }
}

mutation createUserWebhook($config: UserWebhookInput!) {
    createUserWebhook(config: $config) {
        id
    }
}

mutation deleteUserWebhook($id: Int!) {
    deleteUserWebhook(id: $id) {
        id
    }
}

mutation createTrackerWebhook($trackerId: Int!, $config: TrackerWebhookInput!) {
    createTrackerWebhook(trackerId: $trackerId, config: $config) {
        id
    }
}

mutation deleteTrackerWebhook($id: Int!) {
    deleteTrackerWebhook(id: $id) {
        id
    }
}

mutation submitTicket($trackerId: Int!, $input: SubmitTicketInput!) {
    submitTicket(trackerId: $trackerId, input: $input) {
        id
    }
}

mutation labelTicket($trackerId: Int!, $ticketId: Int!, $labelId: Int!) {
    labelTicket(trackerId: $trackerId, ticketId: $ticketId, labelId: $labelId) {
        ticket {
            subject
        }
    }
}

mutation unlabelTicket($trackerId: Int!, $ticketId: Int!, $labelId: Int!) {
    unlabelTicket(
        trackerId: $trackerId
        ticketId: $ticketId
        labelId: $labelId
    ) {
        ticket {
            subject
        }
    }
}
