# Configurations

## Introduction
 - The saved state of a Configurator is called Configuration.
 - The Configuration saves a Variant for each Option used in the Configurator.
 - The Configuration is generated on the server without saving, modified in the frontend and uploaded to the server where it is saved with a code.
 - Each Option can save just one Variant. Options can be used in multiple Scenes. Therefore, using an Option in multiple Scenes causes the selection to be linked between those scenes. If shower and bathroom should be configured individually, each Scene needs its own set of Options.

### Data Versions
The Configuration contains most the data twice:
 - Regular strapi elements that may be updated by the artist at any time.
 - A JSON element that contains the full data of the Configuration as well as the Configurator data at the time of creation of the Configuration. This data should never be changed unless to ensure compatibility of newer Configurator deployments.

As of the 16.10.2023 the JSON data is never used. It should be used in the `/contract` route and whenever the configurator has a code loaded (`?code=ABC123`). Creating an updated, identical Configuration would need the creation of a new code.

## Load-Save Cycle

### Documentation Review 16.10.2023
 - This file seems to still be valid in most parts.
 - The document was used during development. Additional problems might have shown up, but the file at least shows the overall situation. 
 - Saving the configuration by mail was never implemented. The code should still contain the commented out location where we would need to update the backend data of the saved configuration.


### Activity Diagram
``` plantuml
@startuml
!define STYLE_RG
!includeurl https://raw.githubusercontent.com/raumgleiter/PlantUML-Style/master/PlantUML_Style.puml
!include <tupadr3/common>
!include <tupadr3/font-awesome/rocket>
!include <tupadr3/font-awesome-5/user>

' All Skinparams: https://plantuml-documentation.readthedocs.io/en/latest/formatting/all-skin-params.html
' skinparam defaultTextAlignment center

' allowmixing
' skinparam ClassAttributeIconSize 0.1
' skinparam CircledCharacterRadius 0
' skinparam CircledCharacterFontSize 0

'-----------------------------------------------------------------------------

'left to right direction

'******************************************************************************

'-----------------------------------------------------------------------------

start
:Link is opened;
:Load last state from local storage;
if (The locally used code changed) then (no)
  stop
else (yes)
  if (Link contains code) then (no)
    :Ask API for new configuration;
  else (yes)
    :Ask API for existing configuration;
  endif
  :Update configuration;
  if (The locally used code changed) then (yes)
    :Update URL;
  endif
  :Configure on unsaved...;
  :Save to local configuration;
  :Save with API;
  :Update URL;
  fork
    :Select a Variant, etc.;
    :Reset local URL Code;
  forkagain
    :Load different code;
    :Open link;
    stop
  endfork

  :Save to local configuration;
  :Save configuration;
  :Post configuration to API;
  fork
  :Update the code of the loaded page;
  :Choose to save by mail;
  :Add contact to Configuration using API;
  endfork
  stop

endif

'-----------------------------------------------------------------------------

'******************************************************************************

@enduml
```

### Data Diagram
``` plantuml
@startuml
!define STYLE_RG
!includeurl https://raw.githubusercontent.com/raumgleiter/PlantUML-Style/master/PlantUML_Style.puml
!include <tupadr3/common>
!include <tupadr3/font-awesome/rocket>
!include <tupadr3/font-awesome-5/user>

' All Skinparams: https://plantuml-documentation.readthedocs.io/en/latest/formatting/all-skin-params.html
' skinparam defaultTextAlignment center

' allowmixing
' skinparam ClassAttributeIconSize 0.1
' skinparam CircledCharacterRadius 0
' skinparam CircledCharacterFontSize 0

'-----------------------------------------------------------------------------

left to right direction

'******************************************************************************

'-----------------------------------------------------------------------------

class Configuration {
  * code (6 numbers/capsLetters)
  timestamp
  editingAllowed
  urlParameters
}

class OptionSelection {
  selectedVariant
  priceAtSelectionTime
}

class Contact {
  firstName
  lastName
  * mail
}

Configuration "1" -- "*" OptionSelection
OptionSelection --* "1" Option
'Order "*" ..* "1" Contact
'Order ..* "1" Configuration
Contact "1" --o "*" Configuration


'-----------------------------------------------------------------------------

'******************************************************************************

@enduml
```
