@startuml
title PCS Sync - Repository To TIA

actor Engineer
participant "PCS TIA Sync Tool" as Gui
participant "pcs sync status --json" as Status
participant "Repository\n tia/exports" as Repo
participant "pcs deploy" as Deploy
participant "TIA Portal" as TIA
participant "PLC Software" as PLC
participant "pcs sync snapshot tia" as Snapshot
participant "TIA Snapshot\n.pcs/sync/tia-snapshot/latest" as TiaSnapshot

Engineer -> Gui : select Repository --> TIA rows
Gui -> Status : confirm safe candidates
Status --> Gui : Base == TIA, Repo changed
Gui --> Engineer : show direction and normalized diff

Engineer -> Gui : SYNC Repo --> TIA
Gui -> Deploy : selected block/path list
Deploy -> Repo : read selected source files
Deploy -> TIA : attach to open project\nor open through Openness
Deploy -> PLC : generate selected blocks and types
PLC --> Deploy : compile messages
Deploy -> TIA : save project
Deploy --> Gui : deployment result

Gui --> Engineer : ask to capture verification snapshot
Engineer -> Gui : Capture now
Gui -> Snapshot : same project and PLC
Snapshot -> TIA : export generated sources
Snapshot -> TiaSnapshot : replace latest snapshot
Snapshot --> Gui : snapshot captured
Gui -> Status : refresh status
Status --> Gui : Repo == TIA, baseline can be refreshed

@enduml
