# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: "[TC-TBRM-2.2] Initial Dataset configuration of Thread Border Router"

PICS:
    - TBRM.S

config:
    nodeId: 0x12344321
    cluster: Thread Border Router Management
    endpoint: 1
    PIXIT.TBRM.THREAD_ACTIVE_DATASET:
        type: octet_string
        defaultValue: "hex:0e080000000000010000000300001235060004001fffe002082ad51c02fe8f64f20708fddb8af85255f93a051083e2b9b2cc609b00125adbf823ea2ab20102c4d904100a133626c411d7de02a570ca3c3d80470c0402a0f7f8031054687265616441637469766554657374"
        # Active Timestamp ----^^^^^^^^^^^^^^^^
    PIXIT.TBRM.THREAD_ACTIVE_DATASET.ACTIVE_TIMESTAMP: 0x10000
    PIXIT.TBRM.THREAD_INVALID_DATASET:
        type: octet_string
        defaultValue: "hex:00112233"

# Precondition:
# The DUT does not have an Active Dataset

tests:
    - label: "Wait for the commissioned device to be retrieved"
      cluster: DelayCommands
      command: WaitForCommissionee
      arguments:
          values:
              - name: nodeId
                value: nodeId
    # Step 1
    - label: "TH reads the ActiveDatasetTimestamp attribute from the DUT"
      command: readAttribute
      attribute: ActiveDatasetTimestamp
      response:
          value: null

    # Step 2
    - label: "TH reads the PendingDatasetTimestamp attribute from the DUT"
      command: readAttribute
      attribute: PendingDatasetTimestamp
      response:
          value: null

    # Step 3
    - label:
          "TH sends a valid ActiveDatasetRequest command to the DUT without
          having armed the fail-safe"
      command: SetActiveDatasetRequest
      arguments:
          values:
              - name: ActiveDataset
                value: PIXIT.TBRM.THREAD_ACTIVE_DATASET
      response:
          error: FAILSAFE_REQUIRED

    # Step 4
    - label: "TH sends ArmFailSafe command to the DUT"
      cluster: General Commissioning
      command: ArmFailSafe
      endpoint: 0
      arguments:
          values:
              - name: ExpiryLengthSeconds
                value: 60
              - name: Breadcrumb
                value: 1
      response:
          values:
              - name: ErrorCode
                value: CommissioningErrorEnum.OK

    # Step 5
    - label: "TH sends an invalid ActiveDatasetRequest command to the DUT"
      command: SetActiveDatasetRequest
      arguments:
          values:
              - name: ActiveDataset
                value: PIXIT.TBRM.THREAD_INVALID_DATASET
      response:
          error: INVALID_COMMAND

    # Step 6
    - label: "TH sends a valid ActiveDatasetRequest command to the DUT"
      command: SetActiveDatasetRequest
      arguments:
          values:
              - name: ActiveDataset
                value: PIXIT.TBRM.THREAD_ACTIVE_DATASET

    # Step 7
    - label: "TH sends CommissioningComplete command to the DUT"
      cluster: General Commissioning
      command: CommissioningComplete
      endpoint: 0

    # Step 8
    - label: "TH reads the InterfaceEnabled attribute from the DUT"
      command: readAttribute
      attribute: InterfaceEnabled
      response:
          value: true

    # Step 9
    - label: "TH reads the ActiveDatasetTimestamp attribute from the DUT"
      command: readAttribute
      attribute: ActiveDatasetTimestamp
      response:
          value: PIXIT.TBRM.THREAD_ACTIVE_DATASET.ACTIVE_TIMESTAMP
          constraints:
              type: int64u

    # Step 10
    - label: "TH send a GetActiveDatasetRequest command to the DUT"
      command: GetActiveDatasetRequest
      response:
          values:
              - name: Dataset
                value: PIXIT.TBRM.THREAD_ACTIVE_DATASET
                constraints:
                    type: octet_string
