<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (C) 2010-2023 Evolveum and contributors
  ~
  ~ This work is dual-licensed under the Apache License 2.0
  ~ and European Union Public License. See LICENSE file for details.
  -->
<report xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        oid="02d73e64-a638-4c7f-a8fa-7b9623633946">
    <name>Simulation report: Shadows</name>
    <objectCollection>
        <collection>
            <!-- Type is declared in the view element. -->
            <filter>
                <q:text>. ownedByOid `simulationResultRef?.oid`</q:text>
            </filter>
        </collection>
        <view>
            <column>
                <name>id</name>
                <display>
                    <label>ID</label>
                </display>
                <export>
                    <expression>
                        <script>
                            <code>object.id</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>oid</name>
                <path>oid</path>
                <display>
                    <label>OID</label>
                </display>
                <previousColumn>id</previousColumn>
            </column>
            <column>
                <name>name</name>
                <path>name</path>
                <previousColumn>oid</previousColumn>
            </column>
            <column>
                <name>resourceRef</name>
                <path>resourceObjectCoordinates/resourceRef</path>
                <previousColumn>archetype</previousColumn>
            </column>
            <column>
                <name>kind</name>
                <path>resourceObjectCoordinates/kind</path>
                <previousColumn>resourceRef</previousColumn>
            </column>
            <column>
                <name>intent</name>
                <path>resourceObjectCoordinates/intent</path>
                <previousColumn>kind</previousColumn>
            </column>
            <column>
                <name>tag</name>
                <path>resourceObjectCoordinates/tag</path>
                <previousColumn>intent</previousColumn>
            </column>
            <column>
                <name>state</name>
                <path>state</path>
                <previousColumn>tag</previousColumn>
            </column>
            <column>
                <name>eventMarkRef</name>
                <path>eventMarkRef</path>
                <previousColumn>state</previousColumn>
            </column>
            <column>
                <name>itemChanged</name>
                <display>
                    <label>Item changed</label>
                </display>
                <previousColumn>eventMarkRef</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import static com.evolveum.midpoint.model.api.simulation.ProcessedObject.*

                                (itemDelta as ProcessedObjectItemDelta)?.path
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>oldValues</name>
                <display>
                    <label>Old value(s)</label>
                </display>
                <previousColumn>itemChanged</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import static com.evolveum.midpoint.model.api.simulation.ProcessedObject.*

                                (itemDelta as ProcessedObjectItemDelta)?.realValuesBefore
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column>
                <name>newValues</name>
                <display>
                    <label>New value(s)</label>
                </display>
                <previousColumn>oldValues</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import static com.evolveum.midpoint.model.api.simulation.ProcessedObject.*

                                (itemDelta as ProcessedObjectItemDelta)?.realValuesAfter
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <type>c:SimulationResultProcessedObjectType</type>
        </view>
        <parameter>
            <name>simulationResultRef</name>
            <type>c:ObjectReferenceType</type>
            <targetType>SimulationResultType</targetType>
            <display>
                <label>Simulation result</label>
            </display>
        </parameter>
        <subreport>
            <name>itemDelta</name>
            <!-- Returns a list of (non-prism) ProcessedObjectItemDelta objects (EXPERIMENTAL, may change in the future) -->
            <expression>
                <script>
                    <code>
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowCorrelationStateType
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultProcessedObjectType

                        report.getProcessedObjectItemDeltas(
                                object as SimulationResultProcessedObjectType,
                                [
                                        ShadowType.F_KIND,
                                        ShadowType.F_INTENT,
                                        ShadowType.F_CORRELATION.append(ShadowCorrelationStateType.F_SITUATION),
                                        ShadowType.F_CORRELATION.append(ShadowCorrelationStateType.F_RESULTING_OWNER)
                                ],
                                [],
                                false)
                    </code>
                </script>
            </expression>
            <order>10</order>
            <resultHandling>
                <multipleValues>splitParentRow</multipleValues>
            </resultHandling>
        </subreport>
        <subreport>
            <!-- Eliminates rows with no details -->
            <name>detailsPresent</name>
            <type>xsd:boolean</type>
            <expression>
                <script>
                    <code>itemDelta != null ? true : null</code>
                </script>
            </expression>
            <order>20</order>
            <resultHandling>
                <noValues>removeParentRow</noValues>
            </resultHandling>
        </subreport>
    </objectCollection>
</report>
