/**
 * Copyright (c) 2021, 2026 Contributors to the Eclipse Foundation
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 */
import "tutorial.machine" // <1>

activity MoveRobot { // <2>
  prerequisites { // <3>
    Robot1.M at Above_Right
  }
  actions { // <4>
    C: claim Robot1
    R: release Robot1
    A1: move Robot1.M to Below_Right with speed profile slow
    A2: Robot1.C.unclamp
    // Schedule A3 to end together with A4 (As Late As Possible)
    A3: Robot1.C.clamp ALAP // <5>
    A4: move Robot1.M to Above_Right with speed profile normal
  }
  action flow { // <6>
    C -> A1 -> A2 -> |S1 -> A3 -> |S2 -> R 
                     |S1 -> A4 -> |S2 // <7>
  }
}

activity Robot1_GiveTo_Robot2 { 
  prerequisites {
    Robot1.M at Above_Right
    Robot2.M at Above_Right
  }
  actions {
    C1: claim Robot1
    R1: release Robot1
    C2: claim Robot2
    R2: release Robot2
    A2: move Robot1.M to Below_Right with speed profile slow 
    A3: move Robot2.M to Below_Left with speed profile normal
    A4: Robot2.C.clamp
    A5: Robot1.C.unclamp
    A6: move Robot1.M to Above_Right with speed profile normal
    A7: move Robot2.M to Above_Right with speed profile normal
  }
  action flow {
    C1 -> A2 -> |S1                |S2 -> A6 -> R1
    C2 -> A3 -> |S1 -> A4 -> A5 -> |S2 -> A7 -> R2
  }
}

activity Robot1_GiveTo_Robot2_ { 
  prerequisites {
    Robot1.M at Above_Right
    Robot2.M at Above_Right
  }
  actions {
    C1: claim Robot1
    R1: release Robot1
    C2: claim Robot2
    R2: release Robot2
    A3: move Robot2.M to Below_Left with speed profile normal
    A4: Robot2.C.clamp
    A5: Robot1.C.unclamp
    A7: move Robot2.M to Above_Right with speed profile normal
  }
  action flow {
    C2 -> A3 -> C1 -> A4  -> A5 -> R1-> A7 -> R2
  }
}

// ALAP test scenarios

activity ALAP_Scenario_1a {
  actions {
    C: claim Robot1
    R: release Robot1
    // Add ALAP to A1 to get validation warning
    A1: Robot1.C.unclamp
    A2: Robot1.C.clamp
  }
  action flow {
    C -> A1 -> A2 -> R 
  }
}

activity ALAP_Scenario_1b {
  actions {
    C: claim Robot1
    R: release Robot1
    A1: Robot1.C.unclamp
    // Add ALAP to A2 to get validation warning
    A2: Robot1.C.clamp
  }
  action flow {
    C -> A1 -> A2 -> R
  }
}

activity ALAP_Scenario_1c {
  prerequisites {
    Robot1.M at Above_Right
  }
  actions {
    C: claim Robot1
    R: release Robot1
    // Add ALAP to A1 to get validation warning
    A1: Robot1.C.unclamp
    A2: Robot1.C.clamp
    M1: move Robot1.M to Below_Right with speed profile slow
  }
  action flow {
    C -> A1 -> |S1 -> A2 -> |S2 -> R
               |S1 -> M1 -> |S2
  }
}

activity ALAP_Scenario_2 {
  prerequisites {
    Robot2.M at Above_Right
  }
  actions {
    C: claim Robot2
    R: release Robot2
    // Remove ALAP from M1 to get validation error
    M1: move Robot2.M passing Center with speed profile normal ALAP
    M2: move Robot2.M to Below_Left with speed profile normal
    A1: Robot2.C.unclamp
    A2: Robot2.C.clamp
  }
  action flow {
    C -> |S1 -> A1 -> |S2 -> A2 -> |S3 -> R 
         |S1 -> M1 -> |S2 -> M2 -> |S3
  }
}

activity ALAP_Scenario_3 {
  prerequisites {
    Robot2.M at Above_Right
  }
  actions {
    C: claim Robot2
    R: release Robot2
    M1: move Robot2.M passing Center with speed profile normal
    // Add ALAP to M2 to get validation error
    M2: move Robot2.M to Below_Left with speed profile normal
    A1: Robot2.C.unclamp
  }
  action flow {
               |S1 -> A1 -> |S2
    C -> M1 -> |S1 -> M2 -> |S2 -> R
  }
}

activity ALAP_Scenario_4 {
  prerequisites {
    Robot2.M at Above_Right
  }
  actions {
    C: claim Robot2
    R: release Robot2
    //Specify 2 Passing moves and a parallel action
    M1: move Robot2.M passing Center with speed profile normal
    M2: move Robot2.M passing Center_Below_Left with speed profile normal
    M3: move Robot2.M to Below_Left with speed profile normal
    A1: Robot2.C.unclamp
  }
  action flow {
               |S1 -> A1 -> |S2
    C -> M1 -> |S1 -> M2 -> |S2 -> M3 -> R
  }
}
