{% extends "prefixes.sparql" %}
{% block query %}
SELECT DISTINCT ?first_name      ?full_name       ?group_id
                ?uuid ?id        ?institution_id  ?is_active
                ?is_public       ?job_title       ?last_name
                ?orcid_id        ?url_name        ?order_index
WHERE {
  GRAPH <{{state_graph}}> {
    ?author            rdf:type                 djht:Author .
    OPTIONAL { ?author djht:id                  ?id . }

    {%- if item_uri is not none %}
    ?item_uri          rdf:type                 djht:{{prefix}} ;
                       djht:authors             ?authors .
    ?authors           rdf:rest*                ?rest .
    ?rest              rdf:first                ?author ;
                       djht:index               ?order_index .
    {%- endif %}
    {%- if account_uuid is not none %}
    ?container         rdf:type                 djht:{{prefix}}Container .
    {%- if is_published %}
    ?container         djht:published_versions/rdf:rest*/rdf:first ?item_uri .
    {%- else %}
    ?container         djht:draft               ?item_uri .
    {%- endif %}
    ?container         djht:account             <account:{{account_uuid}}> .
    {%- endif %}
    OPTIONAL { ?author djht:first_name          ?first_name . }
    OPTIONAL { ?author djht:full_name           ?full_name . }
    OPTIONAL { ?author djht:group_id            ?group_id . }
    OPTIONAL { ?author djht:institution_id      ?institution_id . }
    OPTIONAL { ?author djht:is_active           ?is_active . }
    OPTIONAL { ?author djht:is_public           ?is_public . }
    OPTIONAL { ?author djht:job_title           ?job_title . }
    OPTIONAL { ?author djht:last_name           ?last_name . }
    OPTIONAL { ?author djht:orcid_id            ?orcid_id . }
    OPTIONAL { ?author djht:url_name            ?url_name . }

    BIND(STRAFTER(STR(?author), "author:") AS ?uuid)
  }
{%- if item_uri is not none %}
  FILTER (?item_uri = <{{item_uri}}>)
{% endif %}
{% if filters is not none %}{{ filters | safe }}{% endif %}
}
{% endblock %}
