<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (C) 2010-2023 Evolveum and contributors
  ~
  ~ Licensed under the EUPL-1.2 or later.
  -->

<report xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
        xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3"
        xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        oid="00000000-0000-0000-0000-ea32deff43df">
    <name>Simulation report: Items changed</name>
    <description>Items changed within individual objects processed by a simulation.</description>
    <assignment id="1">
        <identifier>archetype</identifier>
        <targetRef oid="00000000-0000-0000-0000-000000000171" type="ArchetypeType"/>
    </assignment>
    <objectCollection>
        <collection>
            <!-- Type is declared in the view element. -->
            <filter>
                <q:text>. ownedByOid `simulationResultRef?.oid`</q:text>
            </filter>
        </collection>
        <view>
            <column id="2">
                <name>id</name>
                <display>
                    <label>
                        <t:orig>ID</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.ID</t:key>
                        </t:translation>
                    </label>
                </display>
                <export>
                    <expression>
                        <script>
                            <code>object.id</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="3">
                <name>oid</name>
                <path>oid</path>
                <display>
                    <label>
                        <t:orig>OID</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.OID</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>id</previousColumn>
            </column>
            <column id="4">
                <name>name</name>
                <path>name</path>
                <previousColumn>oid</previousColumn>
            </column>
            <column id="5">
                <name>type</name>
                <path>type</path>
                <previousColumn>name</previousColumn>
            </column>
            <column id="6">
                <name>archetype</name>
                <path>structuralArchetypeRef</path>
                <previousColumn>type</previousColumn>
            </column>
            <column id="7">
                <name>resourceRef</name>
                <path>resourceObjectCoordinates/resourceRef</path>
                <previousColumn>archetype</previousColumn>
            </column>
            <column id="8">
                <name>kind</name>
                <path>resourceObjectCoordinates/kind</path>
                <previousColumn>resourceRef</previousColumn>
            </column>
            <column id="9">
                <name>intent</name>
                <path>resourceObjectCoordinates/intent</path>
                <previousColumn>kind</previousColumn>
            </column>
            <column id="10">
                <name>tag</name>
                <path>resourceObjectCoordinates/tag</path>
                <previousColumn>intent</previousColumn>
            </column>
            <column id="11">
                <name>objectMark</name>
                <display>
                    <label>
                        <t:orig>Object mark</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.objectMark</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>tag</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>objectMarks</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="12">
                <name>state</name>
                <path>state</path>
                <previousColumn>objectMark</previousColumn>
            </column>
            <column id="13">
                <name>resultStatus</name>
                <path>resultStatus</path>
                <previousColumn>state</previousColumn>
            </column>
            <column id="14">
                <name>eventMarkRef</name>
                <path>eventMarkRef</path>
                <previousColumn>resultStatus</previousColumn>
            </column>
            <!-- for each item changed -->
            <column id="15">
                <name>itemChanged</name>
                <display>
                    <label>
                        <t:orig>Item changed</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.itemChanged</t:key>
                        </t:translation>
                    </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 id="16">
                <name>oldValues</name>
                <display>
                    <label>
                        <t:orig>Old value(s)</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.oldValues</t:key>
                        </t:translation>
                    </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 id="17">
                <name>newValues</name>
                <display>
                    <label>
                        <t:orig>New value(s)</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.newValues</t:key>
                        </t:translation>
                    </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>
            <column id="18">
                <name>valuesAdded</name>
                <display>
                    <label>
                        <t:orig>Value(s) added</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.valuesAdded</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>newValues</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import static com.evolveum.midpoint.model.api.simulation.ProcessedObject.*

                                (itemDelta as ProcessedObjectItemDelta)?.realValuesAdded
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="19">
                <name>valuesDeleted</name>
                <display>
                    <label>
                        <t:orig>Value(s) deleted</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.valuesDeleted</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>valuesAdded</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>
                                import static com.evolveum.midpoint.model.api.simulation.ProcessedObject.*

                                (itemDelta as ProcessedObjectItemDelta)?.realValuesDeleted
                            </code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="20">
                <name>relatedAssignment</name>
                <display>
                    <label>
                        <t:orig>Related assignment</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignment</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>valuesDeleted</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="21">
                <name>relatedAssignmentId</name>
                <display>
                    <label>
                        <t:orig>Related assignment ID</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignmentId</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>relatedAssignment</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment?.id</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="22">
                <name>relatedAssignmentTarget</name>
                <display>
                    <label>
                        <t:orig>Related assignment target</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignmentTarget</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>relatedAssignmentId</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment?.targetRef</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="23">
                <name>relatedAssignmentTargetRelation</name>
                <display>
                    <label>
                        <t:orig>Related assignment relation</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignmentTargetRelation</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>relatedAssignmentTarget</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment?.targetRef?.relation</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="24">
                <name>relatedAssignmentResource</name>
                <display>
                    <label>
                        <t:orig>Related assignment resource</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignmentResource</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>relatedAssignmentTargetRelation</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment?.construction?.resourceRef</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="25">
                <name>relatedAssignmentKind</name>
                <display>
                    <label>
                        <t:orig>Related assignment kind</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignmentKind</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>relatedAssignmentResource</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment?.construction?.kind</code>
                        </script>
                    </expression>
                </export>
            </column>
            <column id="26">
                <name>relatedAssignmentIntent</name>
                <display>
                    <label>
                        <t:orig>Related assignment intent</t:orig>
                        <t:translation>
                            <t:key>SimulationReports.column.relatedAssignmentIntent</t:key>
                        </t:translation>
                    </label>
                </display>
                <previousColumn>relatedAssignmentKind</previousColumn>
                <export>
                    <expression>
                        <script>
                            <code>relatedAssignment?.construction?.intent</code>
                        </script>
                    </expression>
                </export>
            </column>
            <type>c:SimulationResultProcessedObjectType</type>
        </view>
        <parameter id="27">
            <name>simulationResultRef</name>
            <type>c:ObjectReferenceType</type>
            <targetType>SimulationResultType</targetType>
            <display>
                <label>
                    <t:orig>simulationResultRef</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.simulationResultRef</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
        <parameter id="28">
            <name>pathsToInclude</name>
            <type>t:ItemPathType</type>
            <display>
                <label>
                    <t:orig>pathsToInclude</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.pathsToInclude</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
        <parameter id="29">
            <name>pathsToExclude</name>
            <type>t:ItemPathType</type>
            <display>
                <label>
                    <t:orig>pathsToExclude</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.pathsToExclude</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
        <parameter id="30">
            <name>includeOperationalItems</name>
            <type>xsd:boolean</type>
            <display>
                <label>
                    <t:orig>includeOperationalItems</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.includeOperationalItems</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
        <parameter id="31">
            <name>showIfNoDetails</name>
            <type>xsd:boolean</type>
            <display>
                <label>
                    <t:orig>showIfNoDetails</t:orig>
                    <t:translation>
                        <t:key>runReportPopupContent.param.name.showIfNoDetails</t:key>
                    </t:translation>
                </label>
            </display>
        </parameter>
        <subreport id="32">
            <name>objectMarks</name>
            <type>c:ObjectReferenceType</type>
            <expression>
                <script>
                    <code>
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultProcessedObjectType

                        report.getObjectMarks(object as SimulationResultProcessedObjectType)
                    </code>
                </script>
            </expression>
            <order>5</order>
        </subreport>
        <subreport id="33">
            <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.SimulationResultProcessedObjectType

                        report.getProcessedObjectItemDeltas(
                                object as SimulationResultProcessedObjectType,
                                pathsToInclude,
                                pathsToExclude,
                                includeOperationalItems)
                    </code>
                </script>
            </expression>
            <order>10</order>
            <resultHandling>
                <multipleValues>splitParentRow</multipleValues>
            </resultHandling>
        </subreport>
        <subreport id="34">
            <!-- Eliminates rows with no details - if requested so -->
            <name>detailsPresent</name>
            <type>xsd:boolean</type>
            <expression>
                <script>
                    <code>showIfNoDetails != false || itemDelta != null ? true : null</code>
                </script>
            </expression>
            <order>20</order>
            <resultHandling>
                <noValues>removeParentRow</noValues>
            </resultHandling>
        </subreport>
        <subreport id="35">
            <name>relatedAssignment</name>
            <type>AssignmentType</type>
            <expression>
                <script>
                    <code>report.getRelatedAssignment(itemDelta)</code>
                </script>
            </expression>
            <order>30</order>
            <resultHandling>
                <multipleValues>splitParentRow</multipleValues>
            </resultHandling>
        </subreport>
    </objectCollection>
</report>
