interface event-queue {
    use http-client.{http-method};
    use headers.{headers};

    // Represents different types of events that can be queued.
    variant event {
        // A GraphQL operation execution event.
        operation(executed-operation),
        // A subgraph request execution event.
        subgraph(executed-subgraph-request),
        // An HTTP request execution event.
        http(executed-http-request),
        // Extension event data as raw bytes.
        extension(extension-event),
    }

    // Info about an executed HTTP request.
    record executed-http-request {
        // The request method.
        method: http-method,
        // The request URL.
        url: string,
        // The response status code.
        status-code: u16,
    }

    // Subgraph response variant.
    variant subgraph-request-execution-kind {
        // Internal server error in the gateway.
        internal-server-error,
        // HTTP request failed.
        request-error,
        // Request was rate-limited.
        rate-limited,
        // A response was received.
        response(subgraph-response),
    }

    // Information on a response
    record subgraph-response {
        // The milliseconds it took to connect to the host.
        connection-time-ns: u64,
        // The milliseconds it took for the host to respond with data.
        response-time-ns: u64,
        // The response status code
        status-code: u16
    }

    // Info about an executed subgraph request.
    record executed-subgraph-request {
        // The name of the subgraph.
        subgraph-name: string,
        // The request method.
        method: http-method,
        // The subgraph URL.
        url: string,
        // The subgraph responses
        executions: list<subgraph-request-execution-kind>,
        // The cache status of the subgraph call.
        cache-status: cache-status,
        // The time in milliseconds taken for the whole operation.
        total-duration-ns: u64,
        // True, if the subgraph returned any errors.
        has-errors: bool,
        // The subgraph response headers.
        response-headers: headers,
    }

    // Info about an executed operation.
    record executed-operation {
        // The name of the operation, if present.
        name: option<string>,
        // The operation document in sanitized form.
        document: string,
        // The time taken in preparing.
        prepare-duration-ns: u64,
        // True, if the plan was taken from cache.
        cached-plan: bool,
        // Time in milliseconds spent executing the operation.
        duration-ns: u64,
        // The status of the operation.
        status: graphql-response-status,
    }

    // A status of a GraphQL operation.
    variant graphql-response-status {
        // Request was successful.
        success,
        // A field returned an error.
        field-error(field-error),
        // A request error.
        request-error(request-error),
        // The request was refused.
        refused-request,
    }

    // An error returned from a field.
    record field-error {
        // The number of errors.
        count: u64,
        // The returned data is null.
        data-is-null: bool,
    }

    // An error from a GraphQL request.
    record request-error {
        // The number of errors.
        count: u64,
    }

    // Cache status of a subgraph call.
    enum cache-status {
        // All data fetched from cache.
        hit,
        // Some data fetched from cache.
        partial-hit,
        // Cache miss
        miss,
    }

    record extension-event {
        extension-name: string,
        event-name: string,
        data: list<u8>
    }

    resource event-queue {
        /// Returns the oldest log entry from the request event queue.
        pop: func() -> option<event>;
    }
}
