terms:
  branes: {}
  avvyland prototype: null
  brane prototype: null
  object prototype: null
  avvyland administrator: null

clauses:
  create brane:
    $do:
      - $if:
          condition:
            $is defined:
              $get:
                term:
                  - "branes"
                  - $subject item: "name"
          is met then:
            $revert:
              error: "the brane already exists"
      - $set:
          term:
            - "branes"
            - $subject item: "name"
          to value:
            $create pactum:
              prototype:
                $get:
                  term: ["brane prototype"]
              terms:
                $subject item: "props"

  set brane prototype:
      $set:
        term: ["brane prototype"]
        to value: $subject

publish:
  $do:
  - $set:
      term: ["avvyland administrator"]
      to value: $sender
  - $set:
      term: ["avvyland prototype"]
      to value:
        $create pactum:
          clauses:
            transfer child:
              $if:
                condition:
                  $is defined:
                    $get:
                      term:
                        - "children"
                        - $subject item: "child"
                is met then:
                  $do:
                    - $execute:
                        clause: ["add child"]
                        of pactum:
                          $subject item: "to parent"
                        subject to:
                          $subject item: "child"
                    - $delete:
                        term:
                          - "children"
                          - $subject item: "child"
                else:
                  $revert:
                    error: "no such child"
            add child:
              $if:
                condition:
                  $is defined:
                    $get:
                      term:
                        - "children"
                        - $subject
                is met then:
                  $revert:
                    error: "the child already exists"
                else:
                  $set:
                    term:
                      - "children"
                      - $subject
                    to value: true
            get object:
              $get:
                term: [ ]

  - $set:
      term: [ "brane prototype" ]
      to value:
        $create pactum:
          clauses:
            transfer child:
              $if:
                condition:
                  $is defined:
                    $get:
                      term:
                        - "children"
                        - $subject item: "child"
                is met then:
                  $do:
                    - $execute:
                        clause: [ "add child" ]
                        of pactum:
                          $subject item: "to parent"
                        subject to:
                          $subject item: "child"
                    - $delete:
                        term:
                          - "children"
                          - $subject item: "child"
                else:
                  $revert:
                    error: "no such child"
            add child:
              $if:
                condition:
                  $is defined:
                    $get:
                      term:
                        - "children"
                        - $subject
                is met then:
                  $revert:
                    error: "the child already exists"
                else:
                  $set:
                    term:
                      - "children"
                      - $subject
                    to value: true
            get object:
              $get:
                term: [ ]
            create child:
              $do:
                - $if:
                    condition:
                      $is not defined:
                        $get:
                          term:
                            - "allowed prototypes"
                            - $subject item: "type"
                    is met then:
                      $revert:
                        error: "no such prototype"
                - $set:
                    local term: [ "created child" ]
                    to value:
                      $create pactum:
                        prototype:
                          $get:
                            term:
                              - "allowed prototypes"
                              - $subject item: "type"
                        terms:
                          $subject item: "props"
                - $set:
                    term:
                      - "children"
                      - $get:
                          local term: [ "created child" ]
                    to value: true
                - $get:
                    local term: [ "created child" ]

            add allowed prototype:
                $set:
                  term:
                    - "allowed prototypes"
                    - $subject item: "type"
                  to value:
                    $subject item: "prototype"

            update settings:
                $set:
                  term: [ "settings" ]
                  to value: $subject
  - $set:
      term: ["object prototype"]
      to value:
        $create pactum:
          clauses:
            transfer child:
              $if:
                condition:
                  $is defined:
                    $get:
                      term:
                        - "children"
                        - $subject item: "child"
                is met then:
                  $do:
                    - $execute:
                        clause: [ "add child" ]
                        of pactum:
                          $subject item: "to parent"
                        subject to:
                          $subject item: "child"
                    - $delete:
                        term:
                          - "children"
                          - $subject item: "child"
                else:
                  $revert:
                    error: "no such child"
            add child:
              $if:
                condition:
                  $is defined:
                    $get:
                      term:
                        - "children"
                        - $subject
                is met then:
                  $revert:
                    error: "the child already exists"
                else:
                  $set:
                    term:
                      - "children"
                      - $subject
                    to value: true
            get object:
              $get:
                term: [ ]
            transform:
              $set:
                term: [ "transformation" ]
                to value: $subject






