/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import { Attribute, OptionalAttribute, OptionalCommand, TlvNoResponse, Event } from "../cluster/Cluster.js";
import { TlvArray } from "../tlv/TlvArray.js";
import { TlvField, TlvObject, TlvOptionalField } from "../tlv/TlvObject.js";
import { TlvUInt16, TlvEnum, TlvBitmap, TlvUInt32 } from "../tlv/TlvNumber.js";
import { TlvString } from "../tlv/TlvString.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { TlvEndpointNumber } from "../datatype/EndpointNumber.js";
import { Priority } from "../globals/Priority.js";
import { ClusterRegistry } from "../cluster/ClusterRegistry.js";
var Actions;
((Actions2) => {
  let ActionType;
  ((ActionType2) => {
    ActionType2[ActionType2["Other"] = 0] = "Other";
    ActionType2[ActionType2["Scene"] = 1] = "Scene";
    ActionType2[ActionType2["Sequence"] = 2] = "Sequence";
    ActionType2[ActionType2["Automation"] = 3] = "Automation";
    ActionType2[ActionType2["Exception"] = 4] = "Exception";
    ActionType2[ActionType2["Notification"] = 5] = "Notification";
    ActionType2[ActionType2["Alarm"] = 6] = "Alarm";
  })(ActionType = Actions2.ActionType || (Actions2.ActionType = {}));
  Actions2.CommandBits = {
    /**
     * Indicate support for InstantAction command
     */
    instantAction: BitFlag(0),
    /**
     * Indicate support for InstantActionWithTransition command
     */
    instantActionWithTransition: BitFlag(1),
    /**
     * Indicate support for StartAction command
     */
    startAction: BitFlag(2),
    /**
     * Indicate support for StartActionWithDuration command
     */
    startActionWithDuration: BitFlag(3),
    /**
     * Indicate support for StopAction command
     */
    stopAction: BitFlag(4),
    /**
     * Indicate support for PauseAction command
     */
    pauseAction: BitFlag(5),
    /**
     * Indicate support for PauseActionWithDuration command
     */
    pauseActionWithDuration: BitFlag(6),
    /**
     * Indicate support for ResumeAction command
     */
    resumeAction: BitFlag(7),
    /**
     * Indicate support for EnableAction command
     */
    enableAction: BitFlag(8),
    /**
     * Indicate support for EnableActionWithDuration command
     */
    enableActionWithDuration: BitFlag(9),
    /**
     * Indicate support for DisableAction command
     */
    disableAction: BitFlag(10),
    /**
     * Indicate support for DisableActionWithDuration command
     */
    disableActionWithDuration: BitFlag(11)
  };
  let ActionState;
  ((ActionState2) => {
    ActionState2[ActionState2["Inactive"] = 0] = "Inactive";
    ActionState2[ActionState2["Active"] = 1] = "Active";
    ActionState2[ActionState2["Paused"] = 2] = "Paused";
    ActionState2[ActionState2["Disabled"] = 3] = "Disabled";
  })(ActionState = Actions2.ActionState || (Actions2.ActionState = {}));
  Actions2.TlvAction = TlvObject({
    /**
     * This field shall provide an unique identifier used to identify an action.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.6.1
     */
    actionId: TlvField(0, TlvUInt16),
    /**
     * This field shall indicate the name (as assigned by the user or automatically by the server) associated with
     * this action. This can be used for identifying the action to the user by the client. Example: "my colorful
     * scene".
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.6.2
     */
    name: TlvField(1, TlvString.bound({ maxLength: 128 })),
    /**
     * This field shall indicate the type of action. The value of Type of an action, along with its
     * SupportedCommands can be used by the client in its UX or logic to determine how to present or use such
     * action. See ActionTypeEnum for details and examples.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.6.3
     */
    type: TlvField(2, TlvEnum()),
    /**
     * This field shall provide a reference to the associated endpoint list, which specifies the endpoints on this
     * Node which will be impacted by this ActionID.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.6.4
     */
    endpointListId: TlvField(3, TlvUInt16),
    /**
     * This field is a bitmap which shall be used to indicate which of the cluster’s commands are supported for this
     * particular action, with a bit set to 1 for each supported command according to the table below. Other bits
     * shall be set to 0.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.6.5
     */
    supportedCommands: TlvField(4, TlvBitmap(TlvUInt16, Actions2.CommandBits)),
    /**
     * This field shall indicate the current state of this action.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.6.6
     */
    state: TlvField(5, TlvEnum())
  });
  let EndpointListType;
  ((EndpointListType2) => {
    EndpointListType2[EndpointListType2["Other"] = 0] = "Other";
    EndpointListType2[EndpointListType2["Room"] = 1] = "Room";
    EndpointListType2[EndpointListType2["Zone"] = 2] = "Zone";
  })(EndpointListType = Actions2.EndpointListType || (Actions2.EndpointListType = {}));
  Actions2.TlvEndpointList = TlvObject({
    /**
     * This field shall provide an unique identifier used to identify the endpoint list.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.7.1
     */
    endpointListId: TlvField(0, TlvUInt16),
    /**
     * This field shall indicate the name (as assigned by the user or automatically by the server) associated with
     * the set of endpoints in this list. This can be used for identifying the action to the user by the client.
     * Example: "living room".
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.7.2
     */
    name: TlvField(1, TlvString.bound({ maxLength: 128 })),
    /**
     * This field shall indicate the type of endpoint list, see EndpointListTypeEnum.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.7.3
     */
    type: TlvField(2, TlvEnum()),
    /**
     * This field shall provide a list of endpoint numbers.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.4.7.4
     */
    endpoints: TlvField(3, TlvArray(TlvEndpointNumber, { maxLength: 256 }))
  });
  Actions2.TlvInstantActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvInstantActionWithTransitionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32),
    /**
     * This field shall indicate the transition time in 1/10th of seconds.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.6.2.1
     */
    transitionTime: TlvField(2, TlvUInt16)
  });
  Actions2.TlvStartActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvStartActionWithDurationRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32),
    /**
     * This field shall indicate the requested duration in seconds.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.6.4.1
     */
    duration: TlvField(2, TlvUInt32)
  });
  Actions2.TlvStopActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvPauseActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvPauseActionWithDurationRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32),
    /**
     * This field shall indicate the requested duration in seconds.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.6.7.1
     */
    duration: TlvField(2, TlvUInt32)
  });
  Actions2.TlvResumeActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvEnableActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvEnableActionWithDurationRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32),
    /**
     * This field shall indicate the requested duration in seconds.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.6.10.1
     */
    duration: TlvField(2, TlvUInt32)
  });
  Actions2.TlvDisableActionRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32)
  });
  Actions2.TlvDisableActionWithDurationRequest = TlvObject({
    actionId: TlvField(0, TlvUInt16),
    invokeId: TlvOptionalField(1, TlvUInt32),
    /**
     * This field shall indicate the requested duration in seconds.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.6.12.1
     */
    duration: TlvField(2, TlvUInt32)
  });
  Actions2.TlvStateChangedEvent = TlvObject({
    /**
     * This field shall be set to the ActionID of the action which has changed state.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.1.1
     */
    actionId: TlvField(0, TlvUInt16),
    /**
     * This field shall be set to the InvokeID which was provided to the most recent command referencing this
     * ActionID.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.1.2
     */
    invokeId: TlvField(1, TlvUInt32),
    /**
     * This field shall be set to state that the action has changed to.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.1.3
     */
    newState: TlvField(2, TlvEnum())
  });
  let ActionError;
  ((ActionError2) => {
    ActionError2[ActionError2["Unknown"] = 0] = "Unknown";
    ActionError2[ActionError2["Interrupted"] = 1] = "Interrupted";
  })(ActionError = Actions2.ActionError || (Actions2.ActionError = {}));
  Actions2.TlvActionFailedEvent = TlvObject({
    /**
     * This field shall be set to the ActionID of the action which encountered an error.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.2.1
     */
    actionId: TlvField(0, TlvUInt16),
    /**
     * This field shall be set to the InvokeID which was provided to the most recent command referencing this
     * ActionID.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.2.2
     */
    invokeId: TlvField(1, TlvUInt32),
    /**
     * This field shall be set to state that the action is in at the time of generating the event.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.2.3
     */
    newState: TlvField(2, TlvEnum()),
    /**
     * This field shall be set to indicate the reason for non-successful progress of the action.
     *
     * @see {@link MatterSpecification.v142.Core} § 9.14.7.2.4
     */
    error: TlvField(3, TlvEnum())
  });
  Actions2.ClusterInstance = MutableCluster({
    id: 37,
    name: "Actions",
    revision: 1,
    attributes: {
      /**
       * The ActionList attribute holds the list of actions. Each entry shall have an unique ActionID, and its
       * EndpointListID shall exist in the EndpointLists attribute.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.5.1
       */
      actionList: Attribute(0, TlvArray(Actions2.TlvAction, { maxLength: 256 }), { default: [] }),
      /**
       * The EndpointLists attribute holds the list of endpoint lists. Each entry shall have an unique
       * EndpointListID.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.5.2
       */
      endpointLists: Attribute(1, TlvArray(Actions2.TlvEndpointList, { maxLength: 256 }), { default: [] }),
      /**
       * The SetupURL attribute (when provided) shall indicate a URL; its syntax shall follow the syntax as
       * specified in RFC 1738, max. 512 ASCII characters and shall use the https scheme. The location referenced
       * by this URL shall provide additional information for the actions provided:
       *
       *   • When used without suffix, it shall provide information about the various actions which the cluster
       *     provides.
       *
       *     ◦ Example: SetupURL could take the value of example://Actions or https://domain.example/
       *       Matter/bridgev1/Actions for this generic case (access generic info how to use actions provided by
       *       this cluster).
       *
       *   • When used with a suffix of "/?a=" and the decimal value of ActionID for one of the actions, it may
       *     provide information about that particular action. This could be a deeplink to
       *     manufacturer-app/website (associated somehow to the server node) with the information/edit-screen for
       *     this action so that the user can view and update details of the action, e.g. edit the scene, or
       *     change the wake-up experience time period.
       *
       *     ◦ Example of SetupURL with suffix added: example://Actions/?a=12345 or
       *       https://domain.example/Matter/bridgev1/Actions/?a=12345 for linking to specific info/editing of the
       *       action with ActionID 0x3039.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.5.3
       */
      setupUrl: OptionalAttribute(2, TlvString.bound({ maxLength: 512 }))
    },
    commands: {
      /**
       * This command is used to trigger an instantaneous action.
       *
       * This command triggers an action (state change) on the involved endpoints, in a "fire and forget" manner.
       * Afterwards, the action’s state shall be Inactive.
       *
       * Example: recall a scene on a number of lights.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.1
       */
      instantAction: OptionalCommand(0, Actions2.TlvInstantActionRequest, 0, TlvNoResponse),
      /**
       * This command is used to trigger an instantaneous action with a transition over a given time.
       *
       * It is recommended that, where possible (e.g., it is not possible for attributes with Boolean data type),
       * a gradual transition SHOULD take place from the old to the new state over this time period. However, the
       * exact transition is manufacturer dependent.
       *
       * This command triggers an action (state change) on the involved endpoints, with a specified time to
       * transition from the current state to the new state. During the transition, the action’s state shall be
       * Active. Afterwards, the action’s state shall be Inactive.
       *
       * Example: recall a scene on a number of lights, with a specified transition time.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.2
       */
      instantActionWithTransition: OptionalCommand(
        1,
        Actions2.TlvInstantActionWithTransitionRequest,
        1,
        TlvNoResponse
      ),
      /**
       * This command is used to trigger the commencement of an action.
       *
       * This command triggers the commencement of an action on the involved endpoints. Afterwards, the action’s
       * state shall be Active.
       *
       * Example: start a dynamic lighting pattern (such as gradually rotating the colors around the setpoints of
       * the scene) on a set of lights.
       *
       * Example: start a sequence of events such as a wake-up experience involving lights moving through several
       * brightness/color combinations and the window covering gradually opening.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.3
       */
      startAction: OptionalCommand(2, Actions2.TlvStartActionRequest, 2, TlvNoResponse),
      /**
       * This command is used to trigger the commencement of an action with a duration.
       *
       * This command triggers the commencement of an action on the involved endpoints, and shall change the
       * action’s state to Active. After the specified Duration, the action will stop, and the action’s state
       * shall change to Inactive.
       *
       * Example: start a dynamic lighting pattern (such as gradually rotating the colors around the setpoints of
       * the scene) on a set of lights for 1 hour (Duration=3600).
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.4
       */
      startActionWithDuration: OptionalCommand(3, Actions2.TlvStartActionWithDurationRequest, 3, TlvNoResponse),
      /**
       * This command is used to stop an action.
       *
       * This command stops the ongoing action on the involved endpoints. Afterwards, the action’s state shall be
       * Inactive.
       *
       * Example: stop a dynamic lighting pattern which was previously started with StartAction.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.5
       */
      stopAction: OptionalCommand(4, Actions2.TlvStopActionRequest, 4, TlvNoResponse),
      /**
       * This command is used to pause an action.
       *
       * This command pauses an ongoing action, and shall change the action’s state to Paused.
       *
       * Example: pause a dynamic lighting effect (the lights stay at their current color) which was previously
       * started with StartAction.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.6
       */
      pauseAction: OptionalCommand(5, Actions2.TlvPauseActionRequest, 5, TlvNoResponse),
      /**
       * This command is used to pause an action with a duration.
       *
       * This command pauses an ongoing action, and shall change the action’s state to Paused. After the specified
       * Duration, the ongoing action will be automatically resumed. which shall change the action’s state to
       * Active.
       *
       * Example: pause a dynamic lighting effect (the lights stay at their current color) for 10 minutes
       * (Duration=600).
       *
       * The difference between Pause/Resume and Disable/Enable is on the one hand semantic (the former is more of
       * a transitionary nature while the latter is more permanent) and on the other hand these can be implemented
       * slightly differently in the implementation of the action (e.g. a Pause would be automatically resumed
       * after some hours or during a nightly reset, while an Disable would remain in effect until explicitly
       * enabled again).
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.7
       */
      pauseActionWithDuration: OptionalCommand(6, Actions2.TlvPauseActionWithDurationRequest, 6, TlvNoResponse),
      /**
       * This command is used to resume an action.
       *
       * This command resumes a previously paused action, and shall change the action’s state to Active.
       *
       * The difference between ResumeAction and StartAction is that ResumeAction will continue the action from
       * the state where it was paused, while StartAction will start the action from the beginning.
       *
       * Example: resume a dynamic lighting effect (the lights' colors will change gradually, continuing from the
       * point they were paused).
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.8
       */
      resumeAction: OptionalCommand(7, Actions2.TlvResumeActionRequest, 7, TlvNoResponse),
      /**
       * This command is used to enable an action.
       *
       * This command enables a certain action or automation. Afterwards, the action’s state shall be Active.
       *
       * Example: enable a motion sensor to control the lights in an area.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.9
       */
      enableAction: OptionalCommand(8, Actions2.TlvEnableActionRequest, 8, TlvNoResponse),
      /**
       * This command is used to enable an action with a duration.
       *
       * This command enables a certain action or automation, and shall change the action’s state to be Active.
       * After the specified Duration, the action or automation will stop, and the action’s state shall change to
       * Disabled.
       *
       * Example: enable a "presence mimicking" behavior for the lights in your home during a vacation; the
       * Duration field is used to indicated the length of your absence from home. After that period, the presence
       * mimicking behavior will no longer control these lights.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.10
       */
      enableActionWithDuration: OptionalCommand(9, Actions2.TlvEnableActionWithDurationRequest, 9, TlvNoResponse),
      /**
       * This command is used to disable an action.
       *
       * This command disables a certain action or automation, and shall change the action’s state to Inactive.
       *
       * Example: disable a motion sensor to no longer control the lights in an area.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.11
       */
      disableAction: OptionalCommand(10, Actions2.TlvDisableActionRequest, 10, TlvNoResponse),
      /**
       * This command is used to disable an action with a duration.
       *
       * This command disables a certain action or automation, and shall change the action’s state to Disabled.
       * After the specified Duration, the action or automation will re-start, and the action’s state shall change
       * to either Inactive or Active, depending on the actions (see Section 9.14.8.4, “Example 4: Wake-up
       * routine” and Section 9.14.8.6, “Example 6: Alarm system”).
       *
       * Example: disable a "wakeup" experience for a period of 1 week when going on holiday (to prevent them from
       * turning on in the morning while you’re not at home). After this period, the wakeup experience will
       * control the lights as before.
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.6.12
       */
      disableActionWithDuration: OptionalCommand(11, Actions2.TlvDisableActionWithDurationRequest, 11, TlvNoResponse)
    },
    events: {
      /**
       * This event shall be generated when there is a change in the State of an ActionID during the execution of
       * an action and the most recent command using that ActionID used an InvokeID data field.
       *
       * It provides feedback to the client about the progress of the action.
       *
       * Example: When InstantActionWithTransition is invoked (with an InvokeID data field), two StateChanged
       * events will be generated:
       *
       *   • one when the transition starts (NewState=Active)
       *
       *   • one when the transition completed (NewState=Inactive)
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.7.1
       */
      stateChanged: Event(0, Priority.Info, Actions2.TlvStateChangedEvent),
      /**
       * This event shall be generated when there is some error which prevents the action from its normal planned
       * execution and the most recent command using that ActionID used an InvokeID data field.
       *
       * It provides feedback to the client about the non-successful progress of the action.
       *
       * Example: When InstantActionWithTransition is invoked (with an InvokeID data field), and another
       * controller changes the state of one or more of the involved endpoints during the transition, thus
       * interrupting the transition triggered by the action, two events would be generated:
       *
       *   • StateChanged when the transition starts (NewState=Active)
       *
       *   • ActionFailed when the interrupting command occurs (NewState=Inactive, Error=interrupted)
       *
       * Example: When InstantActionWithTransition is invoked (with an InvokeID data field = 1), and the same
       * client invokes an InstantAction with (the same or another ActionId and) InvokeID = 2, and this second
       * command interrupts the transition triggered by the first command, these events would be generated:
       *
       *   • StateChanged (InvokeID=1, NewState=Active) when the transition starts
       *
       *   • ActionFailed (InvokeID=2, NewState=Inactive, Error=interrupted) when the second command interrupts
       *     the transition
       *
       *   • StateChanged (InvokeID=2, NewState=Inactive) upon the execution of the action for the second command
       *
       * @see {@link MatterSpecification.v142.Core} § 9.14.7.2
       */
      actionFailed: Event(1, Priority.Info, Actions2.TlvActionFailedEvent)
    }
  });
  Actions2.Cluster = Actions2.ClusterInstance;
  Actions2.Complete = Actions2.Cluster;
})(Actions || (Actions = {}));
const ActionsCluster = Actions.Cluster;
ClusterRegistry.register(Actions.Complete);
export {
  Actions,
  ActionsCluster
};
//# sourceMappingURL=actions.js.map
