<!--
SPDX-FileCopyrightText: 2020-2023 Contributors to the Shapeshifter project

SPDX-License-Identifier: Apache-2.0
-->

# FlexSettlement

The FlexSettlement message is sent by DSOs on a regular basis (typically monthly) to AGRs, in order to initiate settlement.
It includes a list of all FlexOrders placed by the originating party during the settlement period.

```
<FlexSettlement
  Metadata…
  PeriodStart            = Period
  PeriodEnd              = Period
  Currency               = ISO4217Currency
  <FlexOrderSettlement     (0...n)
    Period               = Period
    ContractID           = Text (only if the offer and order refer to a bilateral contract)
    D-PrognosisMessageID = UUID(only if it has been agreed that the baseline is based on D-prognoses)
    BaselineReference    = Text (only if another baseline methodology is used)
    OrderReference       = String
    CongestionPoint      = EntityAddress
    Price                = CurrencyAmount
    Penalty              = CurrencyAmount (optional)
    NetSettlement        = CurrencyAmount
    <ISP                   (0...n)
      Start              = Integer
      Duration           = Integer (optional, default = 1)
      BaselinePower      = Integer
      OrderedFlexPower   = Integer
      ActualPower        = Integer
      DeliveredFlexPower = Integer
      PowerDeficiency    = Integer (optional)
    />
  />
  <ContractSettlement      (0...n, only in case of bilateral contracts)
    ContractID           = Text
    <Period                (0...n)
      Period             = Period
      <ISP                 (0...n)
        Start            = Integer
        Duration         = Integer (optional, default = 1)
        ReservedPower    = Integer
        RequestedPower   = Integer (optional, only if present)
        AvailablePower   = Integer (optional)
        OfferedPower     = Integer (optional, only if present)
        OrderedPower     = Integer (optional, only if present)
      />
    />
  />
/>
```


|                        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|------------------------| |
| Metadata               | The metadata for this message. For details, see [metadata attributes](metadata-attributes.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| PeriodStart            | First Period of the settlement period this message applies to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| PeriodEnd              | Last Period of the settlement period this message applies to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Currency               | ISO 4217 code indicating the currency that applies to all amounts (flex price, penalty and net settlement) in this message.                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| FlexOrderSettlement    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ Period               | Period the FlexOrder refers to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ ContractID           | Reference to the concerning bilateral contract, if it is linked to it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ⇥ MessageID            | MessageID  of the Prognosis message (more specifically: the D-Prognosis) the FlexOrder is based on, if it has been agreed that the baseline is based on D-prognoses.                                                                                                                                                                                                                                                                                                                                                                                                             |
| ⇥ BaselineReference    | Identification of the baseline prognosis, if another baseline methodology is used than based on D-prognoses.                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ⇥ OrderReference       | Order reference assigned by the DSO when originating the FlexOrder.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ⇥ CongestionPoint      | Entity Address of the Congestion Point the FlexOrder applies to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ⇥ Price                | The price accepted for supplying the ordered amount of flexibility as per the referenced FlexOrder messages.                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ⇥ Penalty              | Optional (default zero) penalty due a non-zero PowerDeficiency.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ NetSettlement        | Net settlement amount for this Period: Price minus Penalty                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ⇥ ISP                  |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ ⇥ Start              | Number of the first ISP this element refers to. The first ISP of a day has number 1.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ⇥ ⇥ Duration           | The number of ISPs this element represents. Optional, default value is 1.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ⇥ ⇥ BaselinePower      | Power originally forecast (as per the referenced baseline) for this ISP in Watts.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ⇥ ⇥ OrderedFlexPower   | Amount of flex power ordered (as per the referenced FlexOrder message) for this ISP in Watts.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ⇥ ⇥ ActualPower        | Actual amount of power for this ISP in Watts, as measured/determined by the DSO and allocated to the AGR.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ⇥ ⇥ DeliveredFlexPower | Actual amount of flex power delivered for this ISP in Watts, as determined by the DSO.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ⇥ ⇥ PowerDeficiency    | Optional (default zero) amount of flex power sold but not delivered for this ISP in Watts, as determined by the DSO.                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ContractSettlement     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ ContractID           | Reference to the bilateral contract in question.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ⇥ Period               | List of periods containing reservations                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ⇥ ⇥ Period             | Period the settlement refers to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ⇥ ⇥ ISP                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ ⇥ ⇥ Start            | Number of the first ISP this element refers to. The first ISP of a day has number 1.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ⇥ ⇥ ⇥ Duration         | The number of ISPs this element represents. Optional, default value is 1.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ⇥ ⇥ ⇥ ReservedPower    | Amount of flex power that has been reserved (and not released using a FlexReservationUpdate message)                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ⇥ ⇥ ⇥ RequestedPower   | Amount of flex power that has been both reserved in advance and has been requested using a FlexRequest (i.e. the lowest amount of flex power for this ISP). If there was no FlexRequest, this field is omitted.                                                                                                                                                                                                                                                                                                                                                                  |
| ⇥ ⇥ ⇥ AvailablePower   | Amount of flex power that is considered available based on the FlexRequest in question.</br>In case RequestedPower=0, AvailablePower is defined so that the offered power is allowed to be between 0 and AvailablePower in terms of compliancy (see [Flex reservation mechanism](../../appendix/flex-reservation-mechanism.md) for details).</br>In case RequestedPower ≠0, AvailablePower is defined so that the offered power is allowed to exceed the amount of requested power up to AvailablePower.</br>If this is relevant for settlement, the DSO can include this field. |
| ⇥ ⇥ ⇥ OfferedPower     | Amount of flex power that has been reserved in advance, requested using a FlexRequest and covered in an offer from the AGR. If there was no offer, this field is omitted. If there were multiple offers, only the one is considered that is most compliant (see [Flex reservation mechanism](../../appendix/flex-reservation-mechanism.md) for details about compliancy).                                                                                                                                                                                                        |
| ⇥ ⇥ ⇥ OrderedPower     | Amount of flex power that has been ordered using a FlexOrder message that was based on a FlexOffer, both linked to this contract. If there was no order, this field is omitted.                                                                                                                                                                                                                                                                                                                                                                                                  |
