import * as VScript from "http://172.16.0.12/bladerunner_sdk/vscript@2.5.2/deno/release/mod.ts";
import * as VAPI from "./mod.ts";
export const lift = {
  Channel: (
    _raw: [
      null | string,
      number,
      boolean,
      [number, number, number, number, number],
    ],
    _socket: VScript.VSocket,
  ): Channel => {
    return {
      signal:
        _raw[0] === null
          ? null
          : VScript.VAPIHelpers.liftRefinedIndexedMutatingReference<
              VScript.VSocket,
              "signal_status",
              "Audio::Data::SignalSourceSlice",
              VScript.Referenceable<"Audio::Data::SignalSourceSlice"> &
                VAPI.Audio.SignalSourceSlice,
              VAPI.Audio.SignalStatus,
              VAPI.Audio.SignalStatus
            >(
              (kwl: VScript.KWLName<"full">, _socket: VScript.VSocket) =>
                new VAPI.Audio.SignalSourceSlice(
                  VScript.VAPIHelpers.get_subtree(_socket, kwl),
                ),
              "signal_status" as VScript.SysName,
              {
                lift: (x: any /* FIXME */, _: VScript.VSocket) => x,
                lower: (x: any /* FIXME */, _: VScript.VSocket) => x,
              },
            )(_raw[0], _socket),
      gain: _raw[1],
      phase_invert: _raw[2],
      fade_request: VAPI.Audio.lift.FadeRequest(_raw[3], _socket),
    };
  },
  FadeRequest: (
    _raw: [number, number, number, number, number],
    _socket: VScript.VSocket,
  ): FadeRequest => {
    return {
      start: _raw[0],
      downto: _raw[1],
      upfrom: _raw[2],
      end: _raw[3],
      micro_epoch_index: _raw[4],
    };
  },
  SignalSourceSlice: (_raw: VScript.DataViews.Subtree<VScript.VSocket>) =>
    new SignalSourceSlice(_raw),
} as const;
export const lower = {
  Channel: (
    _x: {
      signal: null | VScript.RefinedIndexedMutatingReference<
        VScript.VSocket,
        "signal_status",
        "Audio::Data::SignalSourceSlice",
        VScript.Referenceable<"Audio::Data::SignalSourceSlice"> &
          VAPI.Audio.SignalSourceSlice,
        VAPI.Audio.SignalStatus,
        VAPI.Audio.SignalStatus
      >;
      gain: number;
      phase_invert: boolean;

      /**
        if `start` < `downto` ≤ `upfrom` < `end`, this corresponds to a
        V-fade request fading down from `start` to `downto` and back up from
        `upfrom` to `end`. If `start` = `downto` = `upfrom` < `end`, the
        essence should be initially set up with zero amplitude and fade to
        full amplitude between `upfrom` and `end`; likewise, `start` <
        `downto` = `upfrom` = `end` should be initialized with full
        amplitude, fade down to zero amplitude between `start` and `downto`
        and remain there indefinitely.
        
        All free-running counter values are measured with respect to micro
        epoch #`micro_epoch_index`.
      */
      fade_request: VAPI.Audio.FadeRequest;
    },
    _socket: VScript.VSocket,
  ): [
    null | string,
    number,
    boolean,
    [number, number, number, number, number],
  ] => [
    _x.signal === null
      ? null
      : VScript.VAPIHelpers.lowerRefinedIndexedReference<
          VScript.VSocket,
          "signal_status",
          "Audio::Data::SignalSourceSlice",
          VScript.Referenceable<"Audio::Data::SignalSourceSlice"> &
            VAPI.Audio.SignalSourceSlice,
          VAPI.Audio.SignalStatus,
          VAPI.Audio.SignalStatus
        >()(_x.signal, _socket),
    _x.gain,
    _x.phase_invert,
    VAPI.Audio.lower.FadeRequest(_x.fade_request, _socket),
  ],
  FadeRequest: (
    _x: {
      start: VAPI.Time.FreeRunningCounter;
      downto: VAPI.Time.FreeRunningCounter;
      upfrom: VAPI.Time.FreeRunningCounter;
      end: VAPI.Time.FreeRunningCounter;
      micro_epoch_index: VAPI.Time.MicroEpochIndex;
    },
    _socket: VScript.VSocket,
  ): [number, number, number, number, number] => [
    _x.start,
    _x.downto,
    _x.upfrom,
    _x.end,
    _x.micro_epoch_index,
  ],
  SignalSourceSlice: (_x: SignalSourceSlice) => _x.raw.kwl,
} as const;
export interface Channel {
  signal: null | VScript.RefinedIndexedMutatingReference<
    VScript.VSocket,
    "signal_status",
    "Audio::Data::SignalSourceSlice",
    VScript.Referenceable<"Audio::Data::SignalSourceSlice"> &
      VAPI.Audio.SignalSourceSlice,
    VAPI.Audio.SignalStatus,
    VAPI.Audio.SignalStatus
  >;
  gain: number;
  phase_invert: boolean;

  /**
    if `start` < `downto` ≤ `upfrom` < `end`, this corresponds to a V-fade
    request fading down from `start` to `downto` and back up from `upfrom` to
    `end`. If `start` = `downto` = `upfrom` < `end`, the essence should be
    initially set up with zero amplitude and fade to full amplitude between
    `upfrom` and `end`; likewise, `start` < `downto` = `upfrom` = `end`
    should be initialized with full amplitude, fade down to zero amplitude
    between `start` and `downto` and remain there indefinitely.
    
    All free-running counter values are measured with respect to micro epoch
    #`micro_epoch_index`.
  */
  fade_request: VAPI.Audio.FadeRequest;
}
export type ChannelIndex = number;
export type Channelcount = number;
/**
  if `start` < `downto` ≤ `upfrom` < `end`, this corresponds to a V-fade
  request fading down from `start` to `downto` and back up from `upfrom` to
  `end`. If `start` = `downto` = `upfrom` < `end`, the essence should be
  initially set up with zero amplitude and fade to full amplitude between
  `upfrom` and `end`; likewise, `start` < `downto` = `upfrom` = `end` should
  be initialized with full amplitude, fade down to zero amplitude between
  `start` and `downto` and remain there indefinitely.
  
  All free-running counter values are measured with respect to micro epoch
  #`micro_epoch_index`.
*/
export interface FadeRequest {
  start: VAPI.Time.FreeRunningCounter;
  downto: VAPI.Time.FreeRunningCounter;
  upfrom: VAPI.Time.FreeRunningCounter;
  end: VAPI.Time.FreeRunningCounter;
  micro_epoch_index: VAPI.Time.MicroEpochIndex;
}
export type Format = "AM824" | "L24" | "L16";
export type Frequency = "F48000" | "F96000";
export type Level = "set_6dbfs" | "set_18dbfs" | "set_20dbfs";
export type PacketTime =
  | "p1"
  | "p0_666"
  | "p0_500"
  | "p0_333"
  | "p0_250"
  | "p0_125";
export type PeakMeter = number;
export type Samplecount = number;
export class SignalSourceSlice
  implements VScript.Referenceable<"Audio::Data::SignalSourceSlice">
{
  readonly type_identifier = "Audio::Data::SignalSourceSlice" as const;
  constructor(readonly raw: VScript.DataViews.Subtree<VScript.VSocket>) {}
  get frequency(): VScript.rKeyword<
    VScript.VSocket,
    null | VAPI.Audio.Frequency,
    null | VAPI.Audio.Frequency,
    VAPI.Audio.SignalSourceSlice
  > {
    return new VScript.rKeyword<
      VScript.VSocket,
      null | VAPI.Audio.Frequency,
      null | VAPI.Audio.Frequency,
      VAPI.Audio.SignalSourceSlice
    >(this, "frequency" as VScript.SysName, {
      lift: (x: any /* FIXME */, _: VScript.VSocket) => x,
      lower: (x: any /* FIXME */, _: VScript.VSocket) => x,
    });
  }
  get peak_meter(): VScript.rKeyword<
    VScript.VSocket,
    Array<number>,
    Array<VAPI.Audio.PeakMeter>,
    VAPI.Audio.SignalSourceSlice
  > {
    return new VScript.rKeyword<
      VScript.VSocket,
      Array<number>,
      Array<VAPI.Audio.PeakMeter>,
      VAPI.Audio.SignalSourceSlice
    >(this, "peak_meter" as VScript.SysName, {
      lift: (x: any /* FIXME */, _: VScript.VSocket) => x,
      lower: (x: any /* FIXME */, _: VScript.VSocket) => x,
    });
  }
  get signal_status(): VScript.rKeywordReferenceable<
    VScript.VSocket,
    "signal_status",
    VAPI.Audio.SignalStatus,
    VAPI.Audio.SignalStatus,
    Array<VAPI.Audio.SignalStatus>,
    Array<VAPI.Audio.SignalStatus>,
    "Audio::Data::SignalSourceSlice",
    VAPI.Audio.SignalSourceSlice
  > {
    return new VScript.rKeywordReferenceable<
      VScript.VSocket,
      "signal_status",
      VAPI.Audio.SignalStatus,
      VAPI.Audio.SignalStatus,
      Array<VAPI.Audio.SignalStatus>,
      Array<VAPI.Audio.SignalStatus>,
      "Audio::Data::SignalSourceSlice",
      VAPI.Audio.SignalSourceSlice
    >(
      this,
      "signal_status" as VScript.SysName,
      {
        lift: (x: any /* FIXME */, _: VScript.VSocket) => x,
        lower: (x: any /* FIXME */, _: VScript.VSocket) => x,
      },
      {
        lift: (x: any /* FIXME */, _: VScript.VSocket) => x,
        lower: (x: any /* FIXME */, _: VScript.VSocket) => x,
      },
    );
  }
  get dt_node(): VScript.rKeyword<
    VScript.VSocket,
    null | VScript.DeviceTreeNodePayload,
    null | VScript.DeviceTreeNodePayload,
    VAPI.Audio.SignalSourceSlice
  > {
    return new VScript.rKeyword<
      VScript.VSocket,
      null | VScript.DeviceTreeNodePayload,
      null | VScript.DeviceTreeNodePayload,
      VAPI.Audio.SignalSourceSlice
    >(this, "dt_node" as VScript.SysName, {
      lift: VScript.VAPIHelpers.liftOrLowerNullable(
        (x: any /* FIXME */, _: VScript.VSocket) => x,
      ),
      lower: VScript.VAPIHelpers.liftOrLowerNullable(
        (x: any /* FIXME */, _: VScript.VSocket) => x,
      ),
    });
  }
}
export type SignalStatus = "NoSignal" | "Silence" | "Signal";
export const Enums = {
  SignalStatus: ["NoSignal", "Silence", "Signal"] as SignalStatus[],
  PacketTime: [
    "p1",
    "p0_666",
    "p0_500",
    "p0_333",
    "p0_250",
    "p0_125",
  ] as PacketTime[],
  Level: ["set_6dbfs", "set_18dbfs", "set_20dbfs"] as Level[],
  Frequency: ["F48000", "F96000"] as Frequency[],
  Format: ["AM824", "L24", "L16"] as Format[],
} as const;
