// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.5
//   protoc               v7.34.1
// source: RealTimeBarsRequest.proto

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

export const protobufPackage = "protobuf";

export interface RealTimeBarsRequest {
  reqId?: number | undefined;
  contract?: Contract | undefined;
  barSize?: number | undefined;
  whatToShow?: string | undefined;
  useRTH?: boolean | undefined;
  realTimeBarsOptions: { [key: string]: string };
}

export interface RealTimeBarsRequest_RealTimeBarsOptionsEntry {
  key: string;
  value: string;
}

function createBaseRealTimeBarsRequest(): RealTimeBarsRequest {
  return {
    reqId: undefined,
    contract: undefined,
    barSize: undefined,
    whatToShow: undefined,
    useRTH: undefined,
    realTimeBarsOptions: {},
  };
}

export const RealTimeBarsRequest: MessageFns<RealTimeBarsRequest> = {
  encode(message: RealTimeBarsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.reqId !== undefined) {
      writer.uint32(8).int32(message.reqId);
    }
    if (message.contract !== undefined) {
      Contract.encode(message.contract, writer.uint32(18).fork()).join();
    }
    if (message.barSize !== undefined) {
      writer.uint32(24).int32(message.barSize);
    }
    if (message.whatToShow !== undefined) {
      writer.uint32(34).string(message.whatToShow);
    }
    if (message.useRTH !== undefined) {
      writer.uint32(40).bool(message.useRTH);
    }
    globalThis.Object.entries(message.realTimeBarsOptions).forEach(([key, value]: [string, string]) => {
      RealTimeBarsRequest_RealTimeBarsOptionsEntry.encode({ key: key as any, value }, writer.uint32(50).fork()).join();
    });
    return writer;
  },

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

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

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

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

          message.whatToShow = reader.string();
          continue;
        }
        case 5: {
          if (tag !== 40) {
            break;
          }

          message.useRTH = reader.bool();
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

          const entry6 = RealTimeBarsRequest_RealTimeBarsOptionsEntry.decode(reader, reader.uint32());
          if (entry6.value !== undefined) {
            message.realTimeBarsOptions[entry6.key] = entry6.value;
          }
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): RealTimeBarsRequest {
    return {
      reqId: isSet(object.reqId) ? globalThis.Number(object.reqId) : undefined,
      contract: isSet(object.contract) ? Contract.fromJSON(object.contract) : undefined,
      barSize: isSet(object.barSize) ? globalThis.Number(object.barSize) : undefined,
      whatToShow: isSet(object.whatToShow) ? globalThis.String(object.whatToShow) : undefined,
      useRTH: isSet(object.useRTH) ? globalThis.Boolean(object.useRTH) : undefined,
      realTimeBarsOptions: isObject(object.realTimeBarsOptions)
        ? (globalThis.Object.entries(object.realTimeBarsOptions) as [string, any][]).reduce(
          (acc: { [key: string]: string }, [key, value]: [string, any]) => {
            acc[key] = globalThis.String(value);
            return acc;
          },
          {},
        )
        : {},
    };
  },

  toJSON(message: RealTimeBarsRequest): unknown {
    const obj: any = {};
    if (message.reqId !== undefined) {
      obj.reqId = Math.round(message.reqId);
    }
    if (message.contract !== undefined) {
      obj.contract = Contract.toJSON(message.contract);
    }
    if (message.barSize !== undefined) {
      obj.barSize = Math.round(message.barSize);
    }
    if (message.whatToShow !== undefined) {
      obj.whatToShow = message.whatToShow;
    }
    if (message.useRTH !== undefined) {
      obj.useRTH = message.useRTH;
    }
    if (message.realTimeBarsOptions) {
      const entries = globalThis.Object.entries(message.realTimeBarsOptions) as [string, string][];
      if (entries.length > 0) {
        obj.realTimeBarsOptions = {};
        entries.forEach(([k, v]) => {
          obj.realTimeBarsOptions[k] = v;
        });
      }
    }
    return obj;
  },

  create(base?: DeepPartial<RealTimeBarsRequest>): RealTimeBarsRequest {
    return RealTimeBarsRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<RealTimeBarsRequest>): RealTimeBarsRequest {
    const message = createBaseRealTimeBarsRequest();
    message.reqId = object.reqId ?? undefined;
    message.contract = (object.contract !== undefined && object.contract !== null)
      ? Contract.fromPartial(object.contract)
      : undefined;
    message.barSize = object.barSize ?? undefined;
    message.whatToShow = object.whatToShow ?? undefined;
    message.useRTH = object.useRTH ?? undefined;
    message.realTimeBarsOptions = (globalThis.Object.entries(object.realTimeBarsOptions ?? {}) as [string, string][])
      .reduce((acc: { [key: string]: string }, [key, value]: [string, string]) => {
        if (value !== undefined) {
          acc[key] = globalThis.String(value);
        }
        return acc;
      }, {});
    return message;
  },
};

function createBaseRealTimeBarsRequest_RealTimeBarsOptionsEntry(): RealTimeBarsRequest_RealTimeBarsOptionsEntry {
  return { key: "", value: "" };
}

export const RealTimeBarsRequest_RealTimeBarsOptionsEntry: MessageFns<RealTimeBarsRequest_RealTimeBarsOptionsEntry> = {
  encode(
    message: RealTimeBarsRequest_RealTimeBarsOptionsEntry,
    writer: BinaryWriter = new BinaryWriter(),
  ): BinaryWriter {
    if (message.key !== "") {
      writer.uint32(10).string(message.key);
    }
    if (message.value !== "") {
      writer.uint32(18).string(message.value);
    }
    return writer;
  },

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

          message.key = reader.string();
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

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

  fromJSON(object: any): RealTimeBarsRequest_RealTimeBarsOptionsEntry {
    return {
      key: isSet(object.key) ? globalThis.String(object.key) : "",
      value: isSet(object.value) ? globalThis.String(object.value) : "",
    };
  },

  toJSON(message: RealTimeBarsRequest_RealTimeBarsOptionsEntry): unknown {
    const obj: any = {};
    if (message.key !== "") {
      obj.key = message.key;
    }
    if (message.value !== "") {
      obj.value = message.value;
    }
    return obj;
  },

  create(
    base?: DeepPartial<RealTimeBarsRequest_RealTimeBarsOptionsEntry>,
  ): RealTimeBarsRequest_RealTimeBarsOptionsEntry {
    return RealTimeBarsRequest_RealTimeBarsOptionsEntry.fromPartial(base ?? {});
  },
  fromPartial(
    object: DeepPartial<RealTimeBarsRequest_RealTimeBarsOptionsEntry>,
  ): RealTimeBarsRequest_RealTimeBarsOptionsEntry {
    const message = createBaseRealTimeBarsRequest_RealTimeBarsOptionsEntry();
    message.key = object.key ?? "";
    message.value = object.value ?? "";
    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>;

function isObject(value: any): boolean {
  return typeof value === "object" && value !== null;
}

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(base?: DeepPartial<T>): T;
  fromPartial(object: DeepPartial<T>): T;
}
