---
to: "sparql_queries_{{ domain | snake_case }}.sparql"
vars:
  domain: "UserManagement"
  description: "SPARQL queries for user management operations"
  ontology_prefix: "user"
  base_uri: "http://example.org/user#"
---
# AI-Generated SPARQL Queries for {{ domain }}
# Description: {{ description }}
# Generated by ggen-ai

PREFIX {{ ontology_prefix }}: <{{ base_uri }}>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

# Query 1: Get all users
SELECT ?user ?name ?email ?createdAt
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:name ?name .
    ?user {{ ontology_prefix }}:email ?email .
    ?user {{ ontology_prefix }}:createdAt ?createdAt .
}
ORDER BY ?name

# Query 2: Find user by email
SELECT ?user ?name ?email ?createdAt
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:name ?name .
    ?user {{ ontology_prefix }}:email "{{ email }}" .
    ?user {{ ontology_prefix }}:createdAt ?createdAt .
}

# Query 3: Get users created after a specific date
SELECT ?user ?name ?email ?createdAt
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:name ?name .
    ?user {{ ontology_prefix }}:email ?email .
    ?user {{ ontology_prefix }}:createdAt ?createdAt .
    FILTER (?createdAt > "{{ start_date }}"^^xsd:dateTime)
}
ORDER BY DESC(?createdAt)

# Query 4: Count users by role
SELECT ?role (COUNT(?user) as ?userCount)
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:hasRole ?role .
}
GROUP BY ?role
ORDER BY DESC(?userCount)

# Query 5: Find users with specific permissions
SELECT ?user ?name ?email ?permission
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:name ?name .
    ?user {{ ontology_prefix }}:email ?email .
    ?user {{ ontology_prefix }}:hasPermission ?permission .
    ?permission rdf:type {{ ontology_prefix }}:Permission .
    FILTER (?permission = {{ ontology_prefix }}:{{ permission_type }})
}

# Query 6: Get user activity summary
SELECT ?user ?name ?activityCount ?lastActivity
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:name ?name .
    {
        SELECT ?user (COUNT(?activity) as ?activityCount) (MAX(?timestamp) as ?lastActivity)
        WHERE {
            ?activity {{ ontology_prefix }}:performedBy ?user .
            ?activity {{ ontology_prefix }}:timestamp ?timestamp .
        }
        GROUP BY ?user
    }
}
ORDER BY DESC(?activityCount)

# Query 7: Find inactive users (no activity in last 30 days)
SELECT ?user ?name ?email ?lastActivity
WHERE {
    ?user rdf:type {{ ontology_prefix }}:User .
    ?user {{ ontology_prefix }}:name ?name .
    ?user {{ ontology_prefix }}:email ?email .
    {
        SELECT ?user (MAX(?timestamp) as ?lastActivity)
        WHERE {
            ?activity {{ ontology_prefix }}:performedBy ?user .
            ?activity {{ ontology_prefix }}:timestamp ?timestamp .
        }
        GROUP BY ?user
    }
    FILTER (?lastActivity < "{{ cutoff_date }}"^^xsd:dateTime)
}
ORDER BY ?lastActivity

