{
    "@context": [
        "https://secorolab.github.io/metamodels/acceptance-criteria/bdd/bdd.json",
        "https://secorolab.github.io/metamodels/acceptance-criteria/bdd/behaviour.json",
        "https://secorolab.github.io/metamodels/acceptance-criteria/bdd/task.json",
        "https://secorolab.github.io/metamodels/time-constraint.json",
        {
            "tmpl": "https://secorolab.github.io/models/acceptance-criteria/bdd/templates/",
            "scene": "https://secorolab.github.io/models/acceptance-criteria/bdd/scenes/secorolab/"
        }
    ],
    "@graph": [
        { "@id": "tmpl:bhv-pickplace", "@type": ["bhv:Behaviour", "bhv:Pick", "bhv:Place"] },
        { "@id": "tmpl:task-sorting", "@type": "task:Task" },

        { "@id": "tmpl:evt-pick-start", "@type": "time:Instant" },
        { "@id": "tmpl:evt-place-end", "@type": "time:Instant" },
        { "@id": "tmpl:evt-sort-end", "@type": "time:Instant" },
        { "@id": "tmpl:evt-scr-start", "@type": "time:Instant" },
        { "@id": "tmpl:evt-scr-end", "@type": "time:Instant" },

        { "@id": "tmpl:sorting-given", "@type": "bdd:Given" },
        { "@id": "tmpl:sorting-when", "@type": "bdd:When" },
        { "@id": "tmpl:sorting-then", "@type": "bdd:Then" },
        {
            "@id": "tmpl:scenario-sorting", "@type": "bdd:Scenario",
            "of-behaviour": "tmpl:bhv-pickplace",
            "of-task": "tmpl:task-sorting",
            "given": "tmpl:sorting-given",
            "when": "tmpl:sorting-when",
            "then": "tmpl:sorting-then"
        },

        { "@id": "tmpl:var-pick-ws", "@type": "bdd:ScenarioVariable" },
        { "@id": "tmpl:var-sort-workspaces", "@type": [ "bdd:ScenarioVariable", "bdd:Set" ] },
        { "@id": "tmpl:var-sort-objects", "@type": [ "bdd:ScenarioVariable", "bdd:Set" ] },
        { "@id": "tmpl:var-forall-obj", "@type": "bdd:ScenarioVariable" },
        { "@id": "tmpl:var-exists-ws", "@type": "bdd:ScenarioVariable" },
        { "@id": "tmpl:var-agent", "@type": "bdd:ScenarioVariable" },

        {
            "@id": "tmpl:forall-sort-objects", "@type": "bdd:ForAll",
            "variable": "tmpl:var-forall-obj", "in-set": "tmpl:var-sort-objects",
            "clause-of": "tmpl:sorting-when",
            "has-clause": [
                "tmpl:flc-located-at-pick-ws", "tmpl:when-pickplace",
                "tmpl:flc-move-safely", "tmpl:exists-place-ws"
            ]
        },

        {
           "@id": "tmpl:flc-located-at-pick-ws",
           "@type": [
                "bdd:FluentClause", "bdd:LocatedAtPredicate", "tc:TimeConstraint", "tc:BeforeEventConstraint"
           ],
           "clause-of": "tmpl:sorting-given",
           "ref-object": "tmpl:var-forall-obj",
           "ref-workspace": "tmpl:var-pick-ws",
           "before-event": "tmpl:evt-pick-start"
        },

        {
            "@id": "tmpl:when-pickplace",
            "@type": ["bdd:WhenBehaviour", "tc:TimeConstraint", "tc:DuringEventsConstraint"],
            "of-behaviour": "tmpl:bhv-pickplace",
            "clause-of": "tmpl:sorting-when",
            "target-obj": "tmpl:var-forall-obj",
            "target-agn": "tmpl:var-agent",
            "target-ws": "tmpl:var-exists-ws",
            "after-event": "tmpl:evt-scr-start", "before-event": "tmpl:evt-scr-end"
        },

        {
            "@id": "tmpl:exists-place-ws", "@type": "bdd:ThereExists",
            "variable": "tmpl:var-exists-ws", "in-set": "tmpl:var-sort-workspaces",
            "clause-of": "tmpl:sorting-then",
            "has-clause": [
                "tmpl:flc-located-at-place-ws"
            ]
        },

        {
           "@id": "tmpl:flc-located-at-place-ws",
           "@type": [
                "bdd:FluentClause", "bdd:LocatedAtPredicate", "tc:TimeConstraint", "tc:AfterEventConstraint"
           ],
           "clause-of": "tmpl:sorting-then",
           "ref-object": "tmpl:var-forall-obj",
           "ref-workspace": "tmpl:var-exists-ws",
           "after-event": "tmpl:evt-place-end"
        },

        {
           "@id": "tmpl:flc-move-safely",
           "@type": [
                "bdd:FluentClause", "bdd:MoveSafelyPredicate", "tc:TimeConstraint", "tc:DuringEventsConstraint"
           ],
           "clause-of": "tmpl:sorting-then",
           "ref-agent": "tmpl:var-agent",
           "after-event": "tmpl:evt-pick-start", "before-event": "tmpl:evt-place-end"
        },

        {
           "@id": "tmpl:flc-sorted",
           "@type": [
                "bdd:FluentClause", "bdd:SortedIntoPredicate", "tc:TimeConstraint", "tc:AfterEventConstraint"
           ],
           "clause-of": "tmpl:sorting-then",
           "ref-object": "tmpl:var-sort-objects",
           "ref-workspace": "tmpl:var-sort-workspaces",
           "after-event": "tmpl:evt-sort-end"
        },

        {
            "@id": "tmpl:tmpl-sorting",
            "@type": ["bdd:ScenarioTemplate", "tc:TimeConstraint", "tc:DuringEventsConstraint"],
            "of-scenario": "tmpl:scenario-sorting",
            "has-scene": "scene:scn-pickplace",
            "has-clause": [
                "tmpl:forall-sort-objects", "tmpl:flc-sorted"
            ],
            "after-event": "tmpl:evt-scr-start", "before-event": "tmpl:evt-scr-end"
        }
    ]
}
