@prefix wf: <https://ggen.ai/ontology/workflow#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dcterms: <http://purl.org/dc/terms/> .

# Ontology Definition
wf: a owl:Ontology ;
    dcterms:title "Workflow Automation Engine Ontology" ;
    dcterms:description "BPMN workflows, state machines, event-driven automation, and human-in-the-loop tasks" ;
    dcterms:created "2025-01-08"^^xsd:date ;
    owl:versionInfo "1.0.0" .

# ============================================================================
# CORE CLASSES - Workflow
# ============================================================================

wf:Workflow a owl:Class ;
    rdfs:label "Workflow" ;
    rdfs:comment "Automated workflow definition" .

wf:WorkflowInstance a owl:Class ;
    rdfs:label "Workflow Instance" ;
    rdfs:comment "Running instance of workflow" .

wf:WorkflowEngine a owl:Class ;
    rdfs:label "Workflow Engine" ;
    rdfs:comment "Workflow execution engine" .

wf:WorkflowDefinition a owl:Class ;
    rdfs:label "Workflow Definition" ;
    rdfs:comment "Declarative workflow definition (BPMN, YAML)" .

# ============================================================================
# BPMN CLASSES
# ============================================================================

wf:BPMN_Process a owl:Class ;
    rdfs:subClassOf wf:Workflow ;
    rdfs:label "BPMN Process" ;
    rdfs:comment "Business Process Model and Notation process" .

wf:BPMN_Task a owl:Class ;
    rdfs:label "BPMN Task" ;
    rdfs:comment "BPMN task activity" .

wf:ServiceTask a owl:Class ;
    rdfs:subClassOf wf:BPMN_Task ;
    rdfs:label "Service Task" ;
    rdfs:comment "Automated service invocation" .

wf:UserTask a owl:Class ;
    rdfs:subClassOf wf:BPMN_Task ;
    rdfs:label "User Task" ;
    rdfs:comment "Human task requiring input" .

wf:ScriptTask a owl:Class ;
    rdfs:subClassOf wf:BPMN_Task ;
    rdfs:label "Script Task" ;
    rdfs:comment "Execute inline script" .

wf:SendTask a owl:Class ;
    rdfs:subClassOf wf:BPMN_Task ;
    rdfs:label "Send Task" ;
    rdfs:comment "Send message or notification" .

wf:ReceiveTask a owl:Class ;
    rdfs:subClassOf wf:BPMN_Task ;
    rdfs:label "Receive Task" ;
    rdfs:comment "Wait for external message" .

# ============================================================================
# GATEWAY CLASSES
# ============================================================================

wf:Gateway a owl:Class ;
    rdfs:label "Gateway" ;
    rdfs:comment "Flow control gateway" .

wf:ExclusiveGateway a owl:Class ;
    rdfs:subClassOf wf:Gateway ;
    rdfs:label "Exclusive Gateway (XOR)" ;
    rdfs:comment "Single path based on condition" .

wf:ParallelGateway a owl:Class ;
    rdfs:subClassOf wf:Gateway ;
    rdfs:label "Parallel Gateway (AND)" ;
    rdfs:comment "Execute all paths in parallel" .

wf:InclusiveGateway a owl:Class ;
    rdfs:subClassOf wf:Gateway ;
    rdfs:label "Inclusive Gateway (OR)" ;
    rdfs:comment "Execute one or more paths" .

wf:EventBasedGateway a owl:Class ;
    rdfs:subClassOf wf:Gateway ;
    rdfs:label "Event-Based Gateway" ;
    rdfs:comment "Wait for external event" .

# ============================================================================
# EVENT CLASSES
# ============================================================================

wf:Event a owl:Class ;
    rdfs:label "Event" ;
    rdfs:comment "Workflow event" .

wf:StartEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Start Event" ;
    rdfs:comment "Workflow start trigger" .

wf:EndEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "End Event" ;
    rdfs:comment "Workflow completion" .

wf:IntermediateEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Intermediate Event" ;
    rdfs:comment "Event during workflow execution" .

wf:TimerEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Timer Event" ;
    rdfs:comment "Time-based trigger" .

wf:MessageEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Message Event" ;
    rdfs:comment "Message-based trigger" .

wf:ErrorEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Error Event" ;
    rdfs:comment "Error handling event" .

wf:SignalEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Signal Event" ;
    rdfs:comment "Broadcast signal event" .

wf:ConditionalEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Conditional Event" ;
    rdfs:comment "Condition-based trigger" .

# ============================================================================
# TASK EXECUTION CLASSES
# ============================================================================

wf:Task a owl:Class ;
    rdfs:label "Task" ;
    rdfs:comment "Individual work unit" .

wf:TaskInstance a owl:Class ;
    rdfs:label "Task Instance" ;
    rdfs:comment "Running task instance" .

wf:TaskDefinition a owl:Class ;
    rdfs:label "Task Definition" ;
    rdfs:comment "Task template definition" .

wf:TaskQueue a owl:Class ;
    rdfs:label "Task Queue" ;
    rdfs:comment "Queue of pending tasks" .

wf:TaskAssignment a owl:Class ;
    rdfs:label "Task Assignment" ;
    rdfs:comment "Assign task to user or group" .

# ============================================================================
# SCHEDULING CLASSES
# ============================================================================

wf:Schedule a owl:Class ;
    rdfs:label "Schedule" ;
    rdfs:comment "Task scheduling configuration" .

wf:CronSchedule a owl:Class ;
    rdfs:subClassOf wf:Schedule ;
    rdfs:label "Cron Schedule" ;
    rdfs:comment "Cron expression schedule" .

wf:IntervalSchedule a owl:Class ;
    rdfs:subClassOf wf:Schedule ;
    rdfs:label "Interval Schedule" ;
    rdfs:comment "Fixed interval schedule" .

wf:OneTimeSchedule a owl:Class ;
    rdfs:subClassOf wf:Schedule ;
    rdfs:label "One-Time Schedule" ;
    rdfs:comment "Execute once at specific time" .

# ============================================================================
# STATE MACHINE CLASSES
# ============================================================================

wf:StateMachine a owl:Class ;
    rdfs:label "State Machine" ;
    rdfs:comment "Finite state machine" .

wf:State a owl:Class ;
    rdfs:label "State" ;
    rdfs:comment "Workflow state" .

wf:InitialState a owl:Class ;
    rdfs:subClassOf wf:State ;
    rdfs:label "Initial State" ;
    rdfs:comment "Starting state" .

wf:FinalState a owl:Class ;
    rdfs:subClassOf wf:State ;
    rdfs:label "Final State" ;
    rdfs:comment "Terminal state" .

wf:Transition a owl:Class ;
    rdfs:label "Transition" ;
    rdfs:comment "State transition" .

wf:TransitionCondition a owl:Class ;
    rdfs:label "Transition Condition" ;
    rdfs:comment "Condition for state transition" .

# ============================================================================
# CONDITIONAL BRANCHING CLASSES
# ============================================================================

wf:Condition a owl:Class ;
    rdfs:label "Condition" ;
    rdfs:comment "Boolean condition for branching" .

wf:Expression a owl:Class ;
    rdfs:label "Expression" ;
    rdfs:comment "Conditional expression" .

wf:Branch a owl:Class ;
    rdfs:label "Branch" ;
    rdfs:comment "Conditional branch path" .

wf:Switch a owl:Class ;
    rdfs:label "Switch" ;
    rdfs:comment "Multi-way conditional branching" .

# ============================================================================
# PARALLEL EXECUTION CLASSES
# ============================================================================

wf:ParallelExecution a owl:Class ;
    rdfs:label "Parallel Execution" ;
    rdfs:comment "Execute tasks in parallel" .

wf:Fork a owl:Class ;
    rdfs:label "Fork" ;
    rdfs:comment "Split execution into parallel paths" .

wf:Join a owl:Class ;
    rdfs:label "Join" ;
    rdfs:comment "Wait for all parallel paths to complete" .

wf:Barrier a owl:Class ;
    rdfs:label "Barrier" ;
    rdfs:comment "Synchronization barrier" .

# ============================================================================
# ERROR HANDLING CLASSES
# ============================================================================

wf:ErrorHandler a owl:Class ;
    rdfs:label "Error Handler" ;
    rdfs:comment "Error handling strategy" .

wf:RetryPolicy a owl:Class ;
    rdfs:label "Retry Policy" ;
    rdfs:comment "Automatic retry configuration" .

wf:Timeout a owl:Class ;
    rdfs:label "Timeout" ;
    rdfs:comment "Task timeout configuration" .

wf:CompensationHandler a owl:Class ;
    rdfs:label "Compensation Handler" ;
    rdfs:comment "Rollback compensation logic" .

wf:BoundaryEvent a owl:Class ;
    rdfs:subClassOf wf:Event ;
    rdfs:label "Boundary Event" ;
    rdfs:comment "Event attached to task boundary" .

# ============================================================================
# HUMAN-IN-THE-LOOP CLASSES
# ============================================================================

wf:HumanTask a owl:Class ;
    rdfs:subClassOf wf:Task ;
    rdfs:label "Human Task" ;
    rdfs:comment "Task requiring human input or approval" .

wf:ApprovalTask a owl:Class ;
    rdfs:subClassOf wf:HumanTask ;
    rdfs:label "Approval Task" ;
    rdfs:comment "Approval or rejection task" .

wf:FormTask a owl:Class ;
    rdfs:subClassOf wf:HumanTask ;
    rdfs:label "Form Task" ;
    rdfs:comment "Form submission task" .

wf:ReviewTask a owl:Class ;
    rdfs:subClassOf wf:HumanTask ;
    rdfs:label "Review Task" ;
    rdfs:comment "Document or data review" .

wf:Assignee a owl:Class ;
    rdfs:label "Assignee" ;
    rdfs:comment "User or group assigned to task" .

wf:EscalationPolicy a owl:Class ;
    rdfs:label "Escalation Policy" ;
    rdfs:comment "Task escalation rules" .

# ============================================================================
# AUDIT TRAIL CLASSES
# ============================================================================

wf:AuditLog a owl:Class ;
    rdfs:label "Audit Log" ;
    rdfs:comment "Workflow execution audit trail" .

wf:WorkflowEvent a owl:Class ;
    rdfs:label "Workflow Event" ;
    rdfs:comment "Logged workflow event" .

wf:TaskEvent a owl:Class ;
    rdfs:subClassOf wf:WorkflowEvent ;
    rdfs:label "Task Event" ;
    rdfs:comment "Task-level event" .

wf:StateChangeEvent a owl:Class ;
    rdfs:subClassOf wf:WorkflowEvent ;
    rdfs:label "State Change Event" ;
    rdfs:comment "State transition event" .

# ============================================================================
# VARIABLE & DATA CLASSES
# ============================================================================

wf:Variable a owl:Class ;
    rdfs:label "Variable" ;
    rdfs:comment "Workflow variable" .

wf:InputVariable a owl:Class ;
    rdfs:subClassOf wf:Variable ;
    rdfs:label "Input Variable" ;
    rdfs:comment "Input parameter" .

wf:OutputVariable a owl:Class ;
    rdfs:subClassOf wf:Variable ;
    rdfs:label "Output Variable" ;
    rdfs:comment "Output result" .

wf:ContextVariable a owl:Class ;
    rdfs:subClassOf wf:Variable ;
    rdfs:label "Context Variable" ;
    rdfs:comment "Workflow context data" .

# ============================================================================
# INTEGRATION CLASSES
# ============================================================================

wf:ExternalService a owl:Class ;
    rdfs:label "External Service" ;
    rdfs:comment "External service integration" .

wf:API_Call a owl:Class ;
    rdfs:label "API Call" ;
    rdfs:comment "REST/GraphQL API invocation" .

wf:DatabaseOperation a owl:Class ;
    rdfs:label "Database Operation" ;
    rdfs:comment "Database query or update" .

wf:MessageQueue a owl:Class ;
    rdfs:label "Message Queue" ;
    rdfs:comment "Message queue integration (RabbitMQ, Kafka)" .

# ============================================================================
# PROPERTIES - Workflow
# ============================================================================

wf:workflowName a owl:DatatypeProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range xsd:string ;
    rdfs:label "workflow name" ;
    rdfs:comment "Name of the workflow" .

wf:workflowVersion a owl:DatatypeProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range xsd:string ;
    rdfs:label "workflow version" ;
    rdfs:comment "Version number" .

wf:enabled a owl:DatatypeProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range xsd:boolean ;
    rdfs:label "enabled" ;
    rdfs:comment "Whether workflow is enabled" .

wf:instanceId a owl:DatatypeProperty ;
    rdfs:domain wf:WorkflowInstance ;
    rdfs:range xsd:string ;
    rdfs:label "instance ID" ;
    rdfs:comment "Unique instance identifier" .

wf:status a owl:DatatypeProperty ;
    rdfs:domain wf:WorkflowInstance ;
    rdfs:range xsd:string ;
    rdfs:label "status" ;
    rdfs:comment "Running, completed, failed, suspended" .

# ============================================================================
# PROPERTIES - Task
# ============================================================================

wf:taskName a owl:DatatypeProperty ;
    rdfs:domain wf:Task ;
    rdfs:range xsd:string ;
    rdfs:label "task name" ;
    rdfs:comment "Name of the task" .

wf:taskType a owl:DatatypeProperty ;
    rdfs:domain wf:Task ;
    rdfs:range xsd:string ;
    rdfs:label "task type" ;
    rdfs:comment "Type of task (service, user, script)" .

wf:priority a owl:DatatypeProperty ;
    rdfs:domain wf:Task ;
    rdfs:range xsd:integer ;
    rdfs:label "priority" ;
    rdfs:comment "Task priority (1-10)" .

wf:dueDate a owl:DatatypeProperty ;
    rdfs:domain wf:Task ;
    rdfs:range xsd:dateTime ;
    rdfs:label "due date" ;
    rdfs:comment "Task due date" .

# ============================================================================
# PROPERTIES - Schedule
# ============================================================================

wf:cronExpression a owl:DatatypeProperty ;
    rdfs:domain wf:CronSchedule ;
    rdfs:range xsd:string ;
    rdfs:label "cron expression" ;
    rdfs:comment "Cron expression for scheduling" .

wf:interval a owl:DatatypeProperty ;
    rdfs:domain wf:IntervalSchedule ;
    rdfs:range xsd:duration ;
    rdfs:label "interval" ;
    rdfs:comment "Execution interval" .

wf:startTime a owl:DatatypeProperty ;
    rdfs:domain wf:Schedule ;
    rdfs:range xsd:dateTime ;
    rdfs:label "start time" ;
    rdfs:comment "Schedule start time" .

# ============================================================================
# PROPERTIES - State Machine
# ============================================================================

wf:stateName a owl:DatatypeProperty ;
    rdfs:domain wf:State ;
    rdfs:range xsd:string ;
    rdfs:label "state name" ;
    rdfs:comment "Name of the state" .

wf:transitionEvent a owl:DatatypeProperty ;
    rdfs:domain wf:Transition ;
    rdfs:range xsd:string ;
    rdfs:label "transition event" ;
    rdfs:comment "Event triggering transition" .

wf:conditionExpression a owl:DatatypeProperty ;
    rdfs:domain wf:TransitionCondition ;
    rdfs:range xsd:string ;
    rdfs:label "condition expression" ;
    rdfs:comment "Boolean expression for transition" .

# ============================================================================
# PROPERTIES - Error Handling
# ============================================================================

wf:maxRetries a owl:DatatypeProperty ;
    rdfs:domain wf:RetryPolicy ;
    rdfs:range xsd:integer ;
    rdfs:label "max retries" ;
    rdfs:comment "Maximum retry attempts" .

wf:retryDelay a owl:DatatypeProperty ;
    rdfs:domain wf:RetryPolicy ;
    rdfs:range xsd:duration ;
    rdfs:label "retry delay" ;
    rdfs:comment "Delay between retries" .

wf:backoffMultiplier a owl:DatatypeProperty ;
    rdfs:domain wf:RetryPolicy ;
    rdfs:range xsd:decimal ;
    rdfs:label "backoff multiplier" ;
    rdfs:comment "Exponential backoff multiplier" .

wf:timeoutDuration a owl:DatatypeProperty ;
    rdfs:domain wf:Timeout ;
    rdfs:range xsd:duration ;
    rdfs:label "timeout duration" ;
    rdfs:comment "Task timeout duration" .

# ============================================================================
# PROPERTIES - Audit
# ============================================================================

wf:timestamp a owl:DatatypeProperty ;
    rdfs:domain wf:WorkflowEvent ;
    rdfs:range xsd:dateTime ;
    rdfs:label "timestamp" ;
    rdfs:comment "Event timestamp" .

wf:actor a owl:DatatypeProperty ;
    rdfs:domain wf:WorkflowEvent ;
    rdfs:range xsd:string ;
    rdfs:label "actor" ;
    rdfs:comment "User or service triggering event" .

wf:eventType a owl:DatatypeProperty ;
    rdfs:domain wf:WorkflowEvent ;
    rdfs:range xsd:string ;
    rdfs:label "event type" ;
    rdfs:comment "Type of workflow event" .

# ============================================================================
# OBJECT PROPERTIES - Relationships
# ============================================================================

wf:hasTask a owl:ObjectProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range wf:Task ;
    rdfs:label "has task" ;
    rdfs:comment "Workflow contains task" .

wf:hasState a owl:ObjectProperty ;
    rdfs:domain wf:StateMachine ;
    rdfs:range wf:State ;
    rdfs:label "has state" ;
    rdfs:comment "State machine contains state" .

wf:hasTransition a owl:ObjectProperty ;
    rdfs:domain wf:State ;
    rdfs:range wf:Transition ;
    rdfs:label "has transition" ;
    rdfs:comment "State has outgoing transition" .

wf:hasSchedule a owl:ObjectProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range wf:Schedule ;
    rdfs:label "has schedule" ;
    rdfs:comment "Workflow has schedule" .

wf:hasErrorHandler a owl:ObjectProperty ;
    rdfs:domain wf:Task ;
    rdfs:range wf:ErrorHandler ;
    rdfs:label "has error handler" ;
    rdfs:comment "Task has error handler" .

wf:hasRetryPolicy a owl:ObjectProperty ;
    rdfs:domain wf:Task ;
    rdfs:range wf:RetryPolicy ;
    rdfs:label "has retry policy" ;
    rdfs:comment "Task has retry policy" .

wf:assignedTo a owl:ObjectProperty ;
    rdfs:domain wf:HumanTask ;
    rdfs:range wf:Assignee ;
    rdfs:label "assigned to" ;
    rdfs:comment "Task assigned to user/group" .

wf:hasVariable a owl:ObjectProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range wf:Variable ;
    rdfs:label "has variable" ;
    rdfs:comment "Workflow has variable" .

wf:triggeredBy a owl:ObjectProperty ;
    rdfs:domain wf:Workflow ;
    rdfs:range wf:Event ;
    rdfs:label "triggered by" ;
    rdfs:comment "Workflow triggered by event" .
