// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.2.0
//   protoc               v6.33.4
// source: org/apache/texera/amber/core/workflow.proto

/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { PhysicalOpIdentity } from "./virtualidentity";

export const protobufPackage = "org.apache.texera.amber.core";

export interface PortIdentity {
  id: number;
  internal: boolean;
}

export interface GlobalPortIdentity {
  opId: PhysicalOpIdentity | undefined;
  portId: PortIdentity | undefined;
  input: boolean;
}

export interface InputPort {
  id: PortIdentity | undefined;
  displayName: string;
  disallowMultiLinks: boolean;
  dependencies: PortIdentity[];
}

export interface OutputPort {
  id: PortIdentity | undefined;
  displayName: string;
  blocking: boolean;
  mode: OutputPort_OutputMode;
}

export enum OutputPort_OutputMode {
  /** SET_SNAPSHOT - outputs complete result set snapshot for each update */
  SET_SNAPSHOT = 0,
  /** SET_DELTA - outputs incremental result set delta for each update */
  SET_DELTA = 1,
  /**
   * SINGLE_SNAPSHOT - outputs a single snapshot for the entire execution,
   * used explicitly to support visualization operators that may exceed the memory limit
   * TODO: remove this mode after we have a better solution for output size limit
   */
  SINGLE_SNAPSHOT = 2,
  UNRECOGNIZED = -1,
}

export function outputPort_OutputModeFromJSON(object: any): OutputPort_OutputMode {
  switch (object) {
    case 0:
    case "SET_SNAPSHOT":
      return OutputPort_OutputMode.SET_SNAPSHOT;
    case 1:
    case "SET_DELTA":
      return OutputPort_OutputMode.SET_DELTA;
    case 2:
    case "SINGLE_SNAPSHOT":
      return OutputPort_OutputMode.SINGLE_SNAPSHOT;
    case -1:
    case "UNRECOGNIZED":
    default:
      return OutputPort_OutputMode.UNRECOGNIZED;
  }
}

export function outputPort_OutputModeToJSON(object: OutputPort_OutputMode): string {
  switch (object) {
    case OutputPort_OutputMode.SET_SNAPSHOT:
      return "SET_SNAPSHOT";
    case OutputPort_OutputMode.SET_DELTA:
      return "SET_DELTA";
    case OutputPort_OutputMode.SINGLE_SNAPSHOT:
      return "SINGLE_SNAPSHOT";
    case OutputPort_OutputMode.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}

export interface PhysicalLink {
  fromOpId: PhysicalOpIdentity | undefined;
  fromPortId: PortIdentity | undefined;
  toOpId: PhysicalOpIdentity | undefined;
  toPortId: PortIdentity | undefined;
}

function createBasePortIdentity(): PortIdentity {
  return { id: 0, internal: false };
}

export const PortIdentity: MessageFns<PortIdentity> = {
  encode(message: PortIdentity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== 0) {
      writer.uint32(8).int32(message.id);
    }
    if (message.internal !== false) {
      writer.uint32(16).bool(message.internal);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PortIdentity {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePortIdentity();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.id = reader.int32();
          continue;
        case 2:
          if (tag !== 16) {
            break;
          }

          message.internal = reader.bool();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PortIdentity {
    return {
      id: isSet(object.id) ? globalThis.Number(object.id) : 0,
      internal: isSet(object.internal) ? globalThis.Boolean(object.internal) : false,
    };
  },

  toJSON(message: PortIdentity): unknown {
    const obj: any = {};
    if (message.id !== 0) {
      obj.id = Math.round(message.id);
    }
    if (message.internal !== false) {
      obj.internal = message.internal;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<PortIdentity>, I>>(base?: I): PortIdentity {
    return PortIdentity.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<PortIdentity>, I>>(object: I): PortIdentity {
    const message = createBasePortIdentity();
    message.id = object.id ?? 0;
    message.internal = object.internal ?? false;
    return message;
  },
};

function createBaseGlobalPortIdentity(): GlobalPortIdentity {
  return { opId: undefined, portId: undefined, input: false };
}

export const GlobalPortIdentity: MessageFns<GlobalPortIdentity> = {
  encode(message: GlobalPortIdentity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.opId !== undefined) {
      PhysicalOpIdentity.encode(message.opId, writer.uint32(10).fork()).join();
    }
    if (message.portId !== undefined) {
      PortIdentity.encode(message.portId, writer.uint32(18).fork()).join();
    }
    if (message.input !== false) {
      writer.uint32(24).bool(message.input);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): GlobalPortIdentity {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseGlobalPortIdentity();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.opId = PhysicalOpIdentity.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.portId = PortIdentity.decode(reader, reader.uint32());
          continue;
        case 3:
          if (tag !== 24) {
            break;
          }

          message.input = reader.bool();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): GlobalPortIdentity {
    return {
      opId: isSet(object.opId) ? PhysicalOpIdentity.fromJSON(object.opId) : undefined,
      portId: isSet(object.portId) ? PortIdentity.fromJSON(object.portId) : undefined,
      input: isSet(object.input) ? globalThis.Boolean(object.input) : false,
    };
  },

  toJSON(message: GlobalPortIdentity): unknown {
    const obj: any = {};
    if (message.opId !== undefined) {
      obj.opId = PhysicalOpIdentity.toJSON(message.opId);
    }
    if (message.portId !== undefined) {
      obj.portId = PortIdentity.toJSON(message.portId);
    }
    if (message.input !== false) {
      obj.input = message.input;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<GlobalPortIdentity>, I>>(base?: I): GlobalPortIdentity {
    return GlobalPortIdentity.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<GlobalPortIdentity>, I>>(object: I): GlobalPortIdentity {
    const message = createBaseGlobalPortIdentity();
    message.opId = (object.opId !== undefined && object.opId !== null)
      ? PhysicalOpIdentity.fromPartial(object.opId)
      : undefined;
    message.portId = (object.portId !== undefined && object.portId !== null)
      ? PortIdentity.fromPartial(object.portId)
      : undefined;
    message.input = object.input ?? false;
    return message;
  },
};

function createBaseInputPort(): InputPort {
  return { id: undefined, displayName: "", disallowMultiLinks: false, dependencies: [] };
}

export const InputPort: MessageFns<InputPort> = {
  encode(message: InputPort, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== undefined) {
      PortIdentity.encode(message.id, writer.uint32(10).fork()).join();
    }
    if (message.displayName !== "") {
      writer.uint32(18).string(message.displayName);
    }
    if (message.disallowMultiLinks !== false) {
      writer.uint32(24).bool(message.disallowMultiLinks);
    }
    for (const v of message.dependencies) {
      PortIdentity.encode(v!, writer.uint32(34).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): InputPort {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseInputPort();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.id = PortIdentity.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.displayName = reader.string();
          continue;
        case 3:
          if (tag !== 24) {
            break;
          }

          message.disallowMultiLinks = reader.bool();
          continue;
        case 4:
          if (tag !== 34) {
            break;
          }

          message.dependencies.push(PortIdentity.decode(reader, reader.uint32()));
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): InputPort {
    return {
      id: isSet(object.id) ? PortIdentity.fromJSON(object.id) : undefined,
      displayName: isSet(object.displayName) ? globalThis.String(object.displayName) : "",
      disallowMultiLinks: isSet(object.disallowMultiLinks) ? globalThis.Boolean(object.disallowMultiLinks) : false,
      dependencies: globalThis.Array.isArray(object?.dependencies)
        ? object.dependencies.map((e: any) => PortIdentity.fromJSON(e))
        : [],
    };
  },

  toJSON(message: InputPort): unknown {
    const obj: any = {};
    if (message.id !== undefined) {
      obj.id = PortIdentity.toJSON(message.id);
    }
    if (message.displayName !== "") {
      obj.displayName = message.displayName;
    }
    if (message.disallowMultiLinks !== false) {
      obj.disallowMultiLinks = message.disallowMultiLinks;
    }
    if (message.dependencies?.length) {
      obj.dependencies = message.dependencies.map((e) => PortIdentity.toJSON(e));
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<InputPort>, I>>(base?: I): InputPort {
    return InputPort.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<InputPort>, I>>(object: I): InputPort {
    const message = createBaseInputPort();
    message.id = (object.id !== undefined && object.id !== null) ? PortIdentity.fromPartial(object.id) : undefined;
    message.displayName = object.displayName ?? "";
    message.disallowMultiLinks = object.disallowMultiLinks ?? false;
    message.dependencies = object.dependencies?.map((e) => PortIdentity.fromPartial(e)) || [];
    return message;
  },
};

function createBaseOutputPort(): OutputPort {
  return { id: undefined, displayName: "", blocking: false, mode: 0 };
}

export const OutputPort: MessageFns<OutputPort> = {
  encode(message: OutputPort, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== undefined) {
      PortIdentity.encode(message.id, writer.uint32(10).fork()).join();
    }
    if (message.displayName !== "") {
      writer.uint32(18).string(message.displayName);
    }
    if (message.blocking !== false) {
      writer.uint32(24).bool(message.blocking);
    }
    if (message.mode !== 0) {
      writer.uint32(32).int32(message.mode);
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): OutputPort {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseOutputPort();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.id = PortIdentity.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.displayName = reader.string();
          continue;
        case 3:
          if (tag !== 24) {
            break;
          }

          message.blocking = reader.bool();
          continue;
        case 4:
          if (tag !== 32) {
            break;
          }

          message.mode = reader.int32() as any;
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): OutputPort {
    return {
      id: isSet(object.id) ? PortIdentity.fromJSON(object.id) : undefined,
      displayName: isSet(object.displayName) ? globalThis.String(object.displayName) : "",
      blocking: isSet(object.blocking) ? globalThis.Boolean(object.blocking) : false,
      mode: isSet(object.mode) ? outputPort_OutputModeFromJSON(object.mode) : 0,
    };
  },

  toJSON(message: OutputPort): unknown {
    const obj: any = {};
    if (message.id !== undefined) {
      obj.id = PortIdentity.toJSON(message.id);
    }
    if (message.displayName !== "") {
      obj.displayName = message.displayName;
    }
    if (message.blocking !== false) {
      obj.blocking = message.blocking;
    }
    if (message.mode !== 0) {
      obj.mode = outputPort_OutputModeToJSON(message.mode);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<OutputPort>, I>>(base?: I): OutputPort {
    return OutputPort.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<OutputPort>, I>>(object: I): OutputPort {
    const message = createBaseOutputPort();
    message.id = (object.id !== undefined && object.id !== null) ? PortIdentity.fromPartial(object.id) : undefined;
    message.displayName = object.displayName ?? "";
    message.blocking = object.blocking ?? false;
    message.mode = object.mode ?? 0;
    return message;
  },
};

function createBasePhysicalLink(): PhysicalLink {
  return { fromOpId: undefined, fromPortId: undefined, toOpId: undefined, toPortId: undefined };
}

export const PhysicalLink: MessageFns<PhysicalLink> = {
  encode(message: PhysicalLink, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.fromOpId !== undefined) {
      PhysicalOpIdentity.encode(message.fromOpId, writer.uint32(10).fork()).join();
    }
    if (message.fromPortId !== undefined) {
      PortIdentity.encode(message.fromPortId, writer.uint32(18).fork()).join();
    }
    if (message.toOpId !== undefined) {
      PhysicalOpIdentity.encode(message.toOpId, writer.uint32(26).fork()).join();
    }
    if (message.toPortId !== undefined) {
      PortIdentity.encode(message.toPortId, writer.uint32(34).fork()).join();
    }
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PhysicalLink {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePhysicalLink();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.fromOpId = PhysicalOpIdentity.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.fromPortId = PortIdentity.decode(reader, reader.uint32());
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }

          message.toOpId = PhysicalOpIdentity.decode(reader, reader.uint32());
          continue;
        case 4:
          if (tag !== 34) {
            break;
          }

          message.toPortId = PortIdentity.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PhysicalLink {
    return {
      fromOpId: isSet(object.fromOpId) ? PhysicalOpIdentity.fromJSON(object.fromOpId) : undefined,
      fromPortId: isSet(object.fromPortId) ? PortIdentity.fromJSON(object.fromPortId) : undefined,
      toOpId: isSet(object.toOpId) ? PhysicalOpIdentity.fromJSON(object.toOpId) : undefined,
      toPortId: isSet(object.toPortId) ? PortIdentity.fromJSON(object.toPortId) : undefined,
    };
  },

  toJSON(message: PhysicalLink): unknown {
    const obj: any = {};
    if (message.fromOpId !== undefined) {
      obj.fromOpId = PhysicalOpIdentity.toJSON(message.fromOpId);
    }
    if (message.fromPortId !== undefined) {
      obj.fromPortId = PortIdentity.toJSON(message.fromPortId);
    }
    if (message.toOpId !== undefined) {
      obj.toOpId = PhysicalOpIdentity.toJSON(message.toOpId);
    }
    if (message.toPortId !== undefined) {
      obj.toPortId = PortIdentity.toJSON(message.toPortId);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<PhysicalLink>, I>>(base?: I): PhysicalLink {
    return PhysicalLink.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<PhysicalLink>, I>>(object: I): PhysicalLink {
    const message = createBasePhysicalLink();
    message.fromOpId = (object.fromOpId !== undefined && object.fromOpId !== null)
      ? PhysicalOpIdentity.fromPartial(object.fromOpId)
      : undefined;
    message.fromPortId = (object.fromPortId !== undefined && object.fromPortId !== null)
      ? PortIdentity.fromPartial(object.fromPortId)
      : undefined;
    message.toOpId = (object.toOpId !== undefined && object.toOpId !== null)
      ? PhysicalOpIdentity.fromPartial(object.toOpId)
      : undefined;
    message.toPortId = (object.toPortId !== undefined && object.toPortId !== null)
      ? PortIdentity.fromPartial(object.toPortId)
      : undefined;
    return message;
  },
};

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
  : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function isSet(value: any): boolean {
  return value !== null && value !== undefined;
}

export interface MessageFns<T> {
  encode(message: T, writer?: BinaryWriter): BinaryWriter;
  decode(input: BinaryReader | Uint8Array, length?: number): T;
  fromJSON(object: any): T;
  toJSON(message: T): unknown;
  create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
  fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
