---
# System prepended metadata

title: Untitled

---

```plantuml
@startuml

state Normal {
    state "Get Data From query join" as join
    state "Get Data From tb auto_deploy_product" as tb_deploy
    state "Ext Service evm-inventory" as inv1
    state "Restock" as restock
    state "New Stock" as newstock
    state "Data Auto Deploy Product" as dataFinal
    
state fork_state <<fork>>
[*] -> fork_state
fork_state -> join
join : Get Data By Query Filter voucherStockist, stockistFlagging, brandParent

fork_state -> tb_deploy
tb_deploy : Get Data last sync by created_at desc limit 1

state join_state <<join>>
tb_deploy --> join_state
join --> join_state
join_state --> Eligible
    Eligible: if auto_deploy_product.od_id != complete_order.od_id
join_state --> NotEligible
    NotEligible: stockist user buy from brand but doesn't use voucher or not flagged as stockist
    NotEligible --> dataFinal : set status = unprocessed
Eligible --> Populate
Populate : to model/object
Populate --> inv1
inv1: call endpoint /v1/product-variant-attribute/search
state fork_state2 <<fork>>
inv1 --> fork_state2

fork_state2 --> restock
state restock {
    state "Ext Service evm-inventory" as inv2
    [*] --> model
    model: set status = pending_restock
     model --> inv2
    inv2: call endpoint /v2/internal/stock?isContinueToLog=true
}
fork_state2 --> newstock
state newstock {
    state "Ext Service evm-inventory" as inv3
    state "model" as modelNewStock
    state "Ext Service evm-inventory" as inv4
    [*] --> modelNewStock
    modelNewStock: set status = pending_new_stock
     modelNewStock --> inv3
    inv3: call endpoint /v1/product-variant-mapping/bulk
    inv3 --> inv4
    inv4: call endpoint /v2/internal/stock?            isContinueToLog=true
}

state join_state2 <<join>>
restock --> join_state2
newstock --> join_state2
    
state "Model" as model1
state "Model" as model2
state "Model" as model3
join_state2 --> model1 : success
join_state2 --> model2 : unknown
join_state2 --> model3 : error

    
state join_state3 <<join>>
model1 --> join_state3
    model1: set status = success
model2 --> join_state3
    model2: set status not changed
model3 --> join_state3
    model3: set status = failed

join_state3 --> dataFinal
dataFinal : store to tb_auto_deploy

dataFinal --> [*]
}


@enduml
```