/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import { Attribute, Command } from "../cluster/Cluster.js";
import { TlvArray } from "../tlv/TlvArray.js";
import { TlvString } from "../tlv/TlvString.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { TlvUInt32, TlvBitmap, TlvDouble, TlvEnum, TlvUInt64, TlvUInt8 } from "../tlv/TlvNumber.js";
import { TlvField, TlvOptionalField, TlvObject } from "../tlv/TlvObject.js";
import { TlvNullable } from "../tlv/TlvNullable.js";
import { StatusResponseError } from "../common/StatusResponseError.js";
import { Status as GlobalStatus } from "../globals/Status.js";
import { TlvBoolean } from "../tlv/TlvBoolean.js";
import { ClusterRegistry } from "../cluster/ClusterRegistry.js";
var ContentLauncher;
((ContentLauncher2) => {
  let Feature;
  ((Feature2) => {
    Feature2["ContentSearch"] = "ContentSearch";
    Feature2["UrlPlayback"] = "UrlPlayback";
    Feature2["AdvancedSeek"] = "AdvancedSeek";
    Feature2["TextTracks"] = "TextTracks";
    Feature2["AudioTracks"] = "AudioTracks";
  })(Feature = ContentLauncher2.Feature || (ContentLauncher2.Feature = {}));
  ContentLauncher2.SupportedProtocols = {
    /**
     * Device supports Dynamic Adaptive Streaming over HTTP (DASH)
     */
    dash: BitFlag(0),
    /**
     * Device supports HTTP Live Streaming (HLS)
     */
    hls: BitFlag(1)
  };
  let MetricType;
  ((MetricType2) => {
    MetricType2[MetricType2["Pixels"] = 0] = "Pixels";
    MetricType2[MetricType2["Percentage"] = 1] = "Percentage";
  })(MetricType = ContentLauncher2.MetricType || (ContentLauncher2.MetricType = {}));
  ContentLauncher2.TlvDimension = TlvObject({
    /**
     * This field shall indicate the width using the metric defined in Metric
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.8.1
     */
    width: TlvField(0, TlvDouble),
    /**
     * This field shall indicate the height using the metric defined in Metric
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.8.2
     */
    height: TlvField(1, TlvDouble),
    /**
     * This field shall indicate metric used for defining Height/Width.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.8.3
     */
    metric: TlvField(2, TlvEnum())
  });
  ContentLauncher2.TlvStyleInformation = TlvObject({
    /**
     * This field shall indicate the URL of image used for Styling different Video Player sections like Logo,
     * Watermark etc. The syntax of this field shall follow the syntax as specified in RFC 1738 and shall use the
     * https scheme.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.9.1
     */
    imageUrl: TlvOptionalField(0, TlvString.bound({ maxLength: 8192 })),
    /**
     * This field shall indicate the color, in RGB or RGBA, used for styling different Video Player sections like
     * Logo, Watermark, etc. The value shall conform to the 6-digit or 8-digit format defined for CSS sRGB
     * hexadecimal color notation. Examples:
     *
     *   - #76DE19 for R=0x76, G=0xDE, B=0x19, A absent
     *
     *   - #76DE1980 for R=0x76, G=0xDE, B=0x19, A=0x80
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.9.2
     */
    color: TlvOptionalField(1, TlvString),
    /**
     * This field shall indicate the size of the image used for Styling different Video Player sections like Logo,
     * Watermark etc.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.9.3
     */
    size: TlvOptionalField(2, ContentLauncher2.TlvDimension)
  });
  ContentLauncher2.TlvBrandingInformation = TlvObject({
    /**
     * This field shall indicate name of the provider for the given content.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.10.1
     */
    providerName: TlvField(0, TlvString.bound({ maxLength: 256 })),
    /**
     * This field shall indicate background of the Video Player while content launch request is being processed by
     * it. This background information may also be used by the Video Player when it is in idle state.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.10.2
     */
    background: TlvOptionalField(1, ContentLauncher2.TlvStyleInformation),
    /**
     * This field shall indicate the logo shown when the Video Player is launching. This is also used when the Video
     * Player is in the idle state and Splash field is not available.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.10.3
     */
    logo: TlvOptionalField(2, ContentLauncher2.TlvStyleInformation),
    /**
     * This field shall indicate the style of progress bar for media playback.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.10.4
     */
    progressBar: TlvOptionalField(3, ContentLauncher2.TlvStyleInformation),
    /**
     * This field shall indicate the screen shown when the Video Player is in an idle state. If this property is not
     * populated, the Video Player shall default to logo or the provider name.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.10.5
     */
    splash: TlvOptionalField(4, ContentLauncher2.TlvStyleInformation),
    /**
     * This field shall indicate watermark shown when the media is playing.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.10.6
     */
    watermark: TlvOptionalField(5, ContentLauncher2.TlvStyleInformation)
  });
  ContentLauncher2.TlvTrackPreference = TlvObject({
    /**
     * This field shall contain one of the standard Tags for Identifying Languages RFC 5646, which identifies the
     * primary language used in the Track.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.12.1
     */
    languageCode: TlvField(0, TlvString.bound({ maxLength: 32 })),
    /**
     * This field shall contain a list of enumerated CharacteristicEnum values that indicate a purpose, trait or
     * feature associated with the Track. A value of null shall indicate that there are no Characteristics
     * corresponding to the Track.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.12.2
     */
    characteristics: TlvOptionalField(1, TlvNullable(TlvArray(TlvEnum()))),
    /**
     * This field if present shall indicate the index of the OutputInfoStruct from the OutputList attribute (from
     * the AudioOutput cluster) and indicates which audio output the Audio Track should be played on.
     *
     * This field shall NOT be present if the track is not an audio track.
     *
     * If the track is an audio track, this field MUST be present. A value of null shall indicate that the server
     * can choose the audio output(s) to play the Audio Track on.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.12.3
     */
    audioOutputIndex: TlvOptionalField(2, TlvNullable(TlvUInt8))
  });
  ContentLauncher2.TlvPlaybackPreferences = TlvObject({
    /**
     * This field shall indicate the preferred position (in milliseconds) in the media to launchplaybackfrom. In
     * case the position falls in the middle of a frame, the server shall set the position to the beginning of that
     * frame and set the SampledPosition attribute on the MediaPlaybackclusteraccordingly. A value of null shall
     * indicate that playback position is not applicable for the current state of the media playback. (For example :
     * Live media with no known duration and where seek is not supported).
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.11.1
     */
    playbackPosition: TlvOptionalField(0, TlvNullable(TlvUInt64)),
    /**
     * This field shall indicate the user’s preferred Text Track. A value of null shall indicate that the user did
     * not specify a preferred Text Track on the client. In such a case, the decision to display and select a Text
     * Track is up to the server.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.11.2
     */
    textTrack: TlvOptionalField(1, TlvNullable(ContentLauncher2.TlvTrackPreference)),
    /**
     * This field shall indicate the list of the user’s preferred Audio Tracks. If the list contains multiple
     * values, each AudioTrack must also specify a unique audioOutputIndex to play the track on. A value of null
     * shall indicate that the user did not specify a preferred Audio Track on the client. In such a case, the
     * decision to play and select an Audio Track is up to the server.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.11.3
     */
    audioTracks: TlvOptionalField(2, TlvNullable(TlvArray(ContentLauncher2.TlvTrackPreference)))
  });
  ContentLauncher2.TlvLaunchUrlRequest = TlvObject({
    /**
     * This field shall indicate the URL of content to launch. The syntax of this field shall follow the syntax as
     * specified in RFC 1738 and shall use the https scheme.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.2.1
     */
    contentUrl: TlvField(0, TlvString),
    /**
     * This field, if present, shall provide a string that may be used to describe the content being accessed at the
     * given URL.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.2.2
     */
    displayString: TlvOptionalField(1, TlvString),
    /**
     * This field, if present, shall indicate the branding information that may be displayed when playing back the
     * given content.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.2.3
     */
    brandingInformation: TlvOptionalField(2, ContentLauncher2.TlvBrandingInformation),
    /**
     * This field, if present, shall indicate the user’s preferred Text/AudioTracks and playbackPosition for the
     * media, sent from the client to the server. If the server does not find an available track for the title being
     * played exactly matching a Track requested here, in the list of available tracks, it may default to picking
     * another track that closely matches the requested track. Alternately, it may go with user preferences set on
     * the server side (it will use this option if these PlaybackPreferences are not specified). In the case of text
     * tracks, that may mean that the subtitle text is not displayed at all. In the cases where the preferred
     * Text/AudioTracks are not available, the server shall return the TextTrackNotAvailable and/or
     * AudioTrackNotAvailable Status(es) in the LauncherResponse.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.2.4
     */
    playbackPreferences: TlvOptionalField(3, ContentLauncher2.TlvPlaybackPreferences)
  });
  let Status;
  ((Status2) => {
    Status2[Status2["Success"] = 0] = "Success";
    Status2[Status2["UrlNotAvailable"] = 1] = "UrlNotAvailable";
    Status2[Status2["AuthFailed"] = 2] = "AuthFailed";
    Status2[Status2["TextTrackNotAvailable"] = 3] = "TextTrackNotAvailable";
    Status2[Status2["AudioTrackNotAvailable"] = 4] = "AudioTrackNotAvailable";
  })(Status = ContentLauncher2.Status || (ContentLauncher2.Status = {}));
  class UrlNotAvailableError extends StatusResponseError {
    constructor(message = "Requested URL could not be reached by device", code = GlobalStatus.Failure, clusterCode = 1 /* UrlNotAvailable */) {
      super(message, code, clusterCode);
    }
  }
  ContentLauncher2.UrlNotAvailableError = UrlNotAvailableError;
  class AuthFailedError extends StatusResponseError {
    constructor(message = "Requested URL returned 401 error code", code = GlobalStatus.Failure, clusterCode = 2 /* AuthFailed */) {
      super(message, code, clusterCode);
    }
  }
  ContentLauncher2.AuthFailedError = AuthFailedError;
  class TextTrackNotAvailableError extends StatusResponseError {
    constructor(message = "Requested Text Track (in PlaybackPreferences) not available", code = GlobalStatus.Failure, clusterCode = 3 /* TextTrackNotAvailable */) {
      super(message, code, clusterCode);
    }
  }
  ContentLauncher2.TextTrackNotAvailableError = TextTrackNotAvailableError;
  class AudioTrackNotAvailableError extends StatusResponseError {
    constructor(message = "Requested Audio Track (in PlaybackPreferences) not available", code = GlobalStatus.Failure, clusterCode = 4 /* AudioTrackNotAvailable */) {
      super(message, code, clusterCode);
    }
  }
  ContentLauncher2.AudioTrackNotAvailableError = AudioTrackNotAvailableError;
  ContentLauncher2.TlvLauncherResponse = TlvObject({
    /**
     * This field shall indicate the status of the command which resulted in this response.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.3.1
     */
    status: TlvField(0, TlvEnum()),
    /**
     * This field shall indicate Optional app-specific data.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.3.2
     */
    data: TlvOptionalField(1, TlvString)
  });
  let Parameter;
  ((Parameter2) => {
    Parameter2[Parameter2["Actor"] = 0] = "Actor";
    Parameter2[Parameter2["Channel"] = 1] = "Channel";
    Parameter2[Parameter2["Character"] = 2] = "Character";
    Parameter2[Parameter2["Director"] = 3] = "Director";
    Parameter2[Parameter2["Event"] = 4] = "Event";
    Parameter2[Parameter2["Franchise"] = 5] = "Franchise";
    Parameter2[Parameter2["Genre"] = 6] = "Genre";
    Parameter2[Parameter2["League"] = 7] = "League";
    Parameter2[Parameter2["Popularity"] = 8] = "Popularity";
    Parameter2[Parameter2["Provider"] = 9] = "Provider";
    Parameter2[Parameter2["Sport"] = 10] = "Sport";
    Parameter2[Parameter2["SportsTeam"] = 11] = "SportsTeam";
    Parameter2[Parameter2["Type"] = 12] = "Type";
    Parameter2[Parameter2["Video"] = 13] = "Video";
    Parameter2[Parameter2["Season"] = 14] = "Season";
    Parameter2[Parameter2["Episode"] = 15] = "Episode";
    Parameter2[Parameter2["Any"] = 16] = "Any";
  })(Parameter = ContentLauncher2.Parameter || (ContentLauncher2.Parameter = {}));
  ContentLauncher2.TlvAdditionalInfo = TlvObject({
    /**
     * This field shall indicate the name of external id, ex. "musicbrainz".
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.5.1
     */
    name: TlvField(0, TlvString.bound({ maxLength: 256 })),
    /**
     * This field shall indicate the value for external id, ex. "ST0000000666661".
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.5.2
     */
    value: TlvField(1, TlvString.bound({ maxLength: 8192 }))
  });
  ContentLauncher2.TlvParameterStruct = TlvObject({
    /**
     * This field shall indicate the entity type.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.6.1
     */
    type: TlvField(0, TlvEnum()),
    /**
     * This field shall indicate the entity value, which is a search string, ex. “Manchester by the Sea”.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.6.2
     */
    value: TlvField(1, TlvString.bound({ maxLength: 1024 })),
    /**
     * This field shall indicate the list of additional external content identifiers.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.6.3
     */
    externalIdList: TlvOptionalField(2, TlvArray(ContentLauncher2.TlvAdditionalInfo))
  });
  ContentLauncher2.TlvContentSearch = TlvObject({
    /**
     * This field shall indicate the list of parameters comprising the search. If multiple parameters are provided,
     * the search parameters shall be joined with 'AND' logic. e.g. action movies with Tom Cruise will be
     * represented as [{Actor: 'Tom Cruise'}, {Type: 'Movie'}, {Genre: 'Action'}]
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.5.7.1
     */
    parameterList: TlvField(0, TlvArray(ContentLauncher2.TlvParameterStruct))
  });
  ContentLauncher2.TlvLaunchContentRequest = TlvObject({
    /**
     * This field shall indicate the content to launch.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.1.1
     */
    search: TlvField(0, ContentLauncher2.TlvContentSearch),
    /**
     * This field shall indicate whether to automatically start playing content, where:
     *
     *   - TRUE means best match should start playing automatically.
     *
     *   - FALSE means matches should be displayed on screen for user selection.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.1.2
     */
    autoPlay: TlvField(1, TlvBoolean),
    /**
     * This field, if present, shall indicate app-specific data.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.1.3
     */
    data: TlvOptionalField(2, TlvString),
    /**
     * This field, if present, shall indicate the user’s preferred Text/AudioTracks and playbackPosition for the
     * media, sent from the client to the server. If the server does not find an available track for the title being
     * played exactly matching a Track requested here, in the list of available tracks, it may default to picking
     * another track that closely matches the requested track. Alternately, it may go with user preferences set on
     * the server side (it will use this option if these PlaybackPreferences are not specified). In the case of text
     * tracks, that may mean that the subtitle text is not displayed at all. In the cases where the preferred
     * Text/AudioTracks are not available, the server shall return the TextTrackNotAvailable and/or
     * AudioTrackNotAvailable Status(es) in the LauncherResponse.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.1.4
     */
    playbackPreferences: TlvOptionalField(3, ContentLauncher2.TlvPlaybackPreferences),
    /**
     * This field, if present, shall indicate whether to consider the context of current ongoing activity on the
     * receiver to fulfill the request. For example if the request only includes data in ContentSearch that
     * specifies an Episode number, and UseCurrentContent is set to TRUE, if there is a TV series on going, the
     * request refers to the specific episode of the ongoing season of theTVseries. TRUE means current activity
     * context may be considered FALSE means current activity context shall NOT be considered
     *
     * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.1.5
     */
    useCurrentContext: TlvOptionalField(4, TlvBoolean)
  });
  ContentLauncher2.UrlPlaybackComponent = MutableCluster.Component({
    attributes: {
      /**
       * This attribute shall provide a list of content types supported by the Video Player or Content App in the
       * form of entries in the HTTP "Accept" request header.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 6.7.6.1
       */
      acceptHeader: Attribute(0, TlvArray(TlvString, { maxLength: 100 }), { persistent: true, default: [] }),
      /**
       * This attribute shall provide information about supported streaming protocols.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 6.7.6.2
       */
      supportedStreamingProtocols: Attribute(1, TlvBitmap(TlvUInt32, ContentLauncher2.SupportedProtocols), { persistent: true })
    },
    commands: {
      /**
       * Upon receipt, this shall launch content from the specified URL.
       *
       * The content types supported include those identified in the AcceptHeader and SupportedStreamingProtocols
       * attributes.
       *
       * A check shall be made to ensure the URL is secure (uses HTTPS).
       *
       * When playing a video stream in response to this command, an indication (ex. visual) of the identity of
       * the origin node of the video stream shall be provided. This could be in the form of a friendly name label
       * which uniquely identifies the node to the user. This friendly name label is typically assigned by the
       * Matter Admin (ex. TV) at the time of commissioning and, when it’s a device, is often editable by the
       * user. It might be a combination of a company name and friendly name, for example, ”Acme” or “Acme
       * Streaming Service on Alice’s Phone”.
       *
       * This command returns a Launch Response.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.2
       */
      launchUrl: Command(1, ContentLauncher2.TlvLaunchUrlRequest, 2, ContentLauncher2.TlvLauncherResponse)
    }
  });
  ContentLauncher2.ContentSearchComponent = MutableCluster.Component({
    commands: {
      /**
       * Upon receipt, this shall launch the specified content with optional search criteria.
       *
       * This command returns a Launch Response.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 6.7.7.1
       */
      launchContent: Command(0, ContentLauncher2.TlvLaunchContentRequest, 2, ContentLauncher2.TlvLauncherResponse)
    }
  });
  ContentLauncher2.ContentSearchOrUrlPlaybackComponent = MutableCluster.Component({});
  ContentLauncher2.Base = MutableCluster.Component({
    id: 1290,
    name: "ContentLauncher",
    revision: 2,
    features: {
      /**
       * Device supports content search (non-app specific)
       */
      contentSearch: BitFlag(0),
      /**
       * Device supports basic URL-based file playback
       */
      urlPlayback: BitFlag(1),
      /**
       * Enables clients to implement more advanced media seeking behavior in their user interface, such as for
       * example a "seek bar".
       */
      advancedSeek: BitFlag(2),
      /**
       * Device or app supports Text Tracks.
       */
      textTracks: BitFlag(3),
      /**
       * Device or app supports Audio Tracks.
       */
      audioTracks: BitFlag(4)
    },
    /**
     * This metadata controls which ContentLauncherCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: MutableCluster.Extensions(
      { flags: { urlPlayback: true }, component: ContentLauncher2.UrlPlaybackComponent },
      { flags: { contentSearch: true }, component: ContentLauncher2.ContentSearchComponent },
      { flags: { contentSearch: true }, component: ContentLauncher2.ContentSearchOrUrlPlaybackComponent },
      { flags: { urlPlayback: true }, component: ContentLauncher2.ContentSearchOrUrlPlaybackComponent }
    )
  });
  ContentLauncher2.ClusterInstance = MutableCluster(ContentLauncher2.Base);
  ContentLauncher2.Cluster = ContentLauncher2.ClusterInstance;
  const UP = { urlPlayback: true };
  const CS = { contentSearch: true };
  ContentLauncher2.CompleteInstance = MutableCluster({
    id: ContentLauncher2.Cluster.id,
    name: ContentLauncher2.Cluster.name,
    revision: ContentLauncher2.Cluster.revision,
    features: ContentLauncher2.Cluster.features,
    attributes: {
      acceptHeader: MutableCluster.AsConditional(
        ContentLauncher2.UrlPlaybackComponent.attributes.acceptHeader,
        { mandatoryIf: [UP] }
      ),
      supportedStreamingProtocols: MutableCluster.AsConditional(
        ContentLauncher2.UrlPlaybackComponent.attributes.supportedStreamingProtocols,
        { mandatoryIf: [UP] }
      )
    },
    commands: {
      launchContent: MutableCluster.AsConditional(
        ContentLauncher2.ContentSearchComponent.commands.launchContent,
        { mandatoryIf: [CS] }
      ),
      launchUrl: MutableCluster.AsConditional(ContentLauncher2.UrlPlaybackComponent.commands.launchUrl, { mandatoryIf: [UP] })
    }
  });
  ContentLauncher2.Complete = ContentLauncher2.CompleteInstance;
})(ContentLauncher || (ContentLauncher = {}));
const ContentLauncherCluster = ContentLauncher.Cluster;
ClusterRegistry.register(ContentLauncher.Complete);
export {
  ContentLauncher,
  ContentLauncherCluster
};
//# sourceMappingURL=content-launcher.js.map
