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

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

export const protobufPackage = "protobuf";

export interface HistoricalTicksRequest {
  reqId?: number | undefined;
  contract?: Contract | undefined;
  startDateTime?: string | undefined;
  endDateTime?: string | undefined;
  numberOfTicks?: number | undefined;
  whatToShow?: string | undefined;
  useRTH?: boolean | undefined;
  ignoreSize?: boolean | undefined;
  miscOptions: { [key: string]: string };
}

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

function createBaseHistoricalTicksRequest(): HistoricalTicksRequest {
  return {
    reqId: undefined,
    contract: undefined,
    startDateTime: undefined,
    endDateTime: undefined,
    numberOfTicks: undefined,
    whatToShow: undefined,
    useRTH: undefined,
    ignoreSize: undefined,
    miscOptions: {},
  };
}

export const HistoricalTicksRequest: MessageFns<HistoricalTicksRequest> = {
  encode(message: HistoricalTicksRequest, 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.startDateTime !== undefined) {
      writer.uint32(26).string(message.startDateTime);
    }
    if (message.endDateTime !== undefined) {
      writer.uint32(34).string(message.endDateTime);
    }
    if (message.numberOfTicks !== undefined) {
      writer.uint32(40).int32(message.numberOfTicks);
    }
    if (message.whatToShow !== undefined) {
      writer.uint32(50).string(message.whatToShow);
    }
    if (message.useRTH !== undefined) {
      writer.uint32(56).bool(message.useRTH);
    }
    if (message.ignoreSize !== undefined) {
      writer.uint32(64).bool(message.ignoreSize);
    }
    globalThis.Object.entries(message.miscOptions).forEach(([key, value]: [string, string]) => {
      HistoricalTicksRequest_MiscOptionsEntry.encode({ key: key as any, value }, writer.uint32(74).fork()).join();
    });
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): HistoricalTicksRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseHistoricalTicksRequest();
    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 !== 26) {
            break;
          }

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

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

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

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

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

          message.ignoreSize = reader.bool();
          continue;
        }
        case 9: {
          if (tag !== 74) {
            break;
          }

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

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

  toJSON(message: HistoricalTicksRequest): 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.startDateTime !== undefined) {
      obj.startDateTime = message.startDateTime;
    }
    if (message.endDateTime !== undefined) {
      obj.endDateTime = message.endDateTime;
    }
    if (message.numberOfTicks !== undefined) {
      obj.numberOfTicks = Math.round(message.numberOfTicks);
    }
    if (message.whatToShow !== undefined) {
      obj.whatToShow = message.whatToShow;
    }
    if (message.useRTH !== undefined) {
      obj.useRTH = message.useRTH;
    }
    if (message.ignoreSize !== undefined) {
      obj.ignoreSize = message.ignoreSize;
    }
    if (message.miscOptions) {
      const entries = globalThis.Object.entries(message.miscOptions) as [string, string][];
      if (entries.length > 0) {
        obj.miscOptions = {};
        entries.forEach(([k, v]) => {
          obj.miscOptions[k] = v;
        });
      }
    }
    return obj;
  },

  create(base?: DeepPartial<HistoricalTicksRequest>): HistoricalTicksRequest {
    return HistoricalTicksRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<HistoricalTicksRequest>): HistoricalTicksRequest {
    const message = createBaseHistoricalTicksRequest();
    message.reqId = object.reqId ?? undefined;
    message.contract = (object.contract !== undefined && object.contract !== null)
      ? Contract.fromPartial(object.contract)
      : undefined;
    message.startDateTime = object.startDateTime ?? undefined;
    message.endDateTime = object.endDateTime ?? undefined;
    message.numberOfTicks = object.numberOfTicks ?? undefined;
    message.whatToShow = object.whatToShow ?? undefined;
    message.useRTH = object.useRTH ?? undefined;
    message.ignoreSize = object.ignoreSize ?? undefined;
    message.miscOptions = (globalThis.Object.entries(object.miscOptions ?? {}) 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 createBaseHistoricalTicksRequest_MiscOptionsEntry(): HistoricalTicksRequest_MiscOptionsEntry {
  return { key: "", value: "" };
}

export const HistoricalTicksRequest_MiscOptionsEntry: MessageFns<HistoricalTicksRequest_MiscOptionsEntry> = {
  encode(message: HistoricalTicksRequest_MiscOptionsEntry, 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): HistoricalTicksRequest_MiscOptionsEntry {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseHistoricalTicksRequest_MiscOptionsEntry();
    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): HistoricalTicksRequest_MiscOptionsEntry {
    return {
      key: isSet(object.key) ? globalThis.String(object.key) : "",
      value: isSet(object.value) ? globalThis.String(object.value) : "",
    };
  },

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

  create(base?: DeepPartial<HistoricalTicksRequest_MiscOptionsEntry>): HistoricalTicksRequest_MiscOptionsEntry {
    return HistoricalTicksRequest_MiscOptionsEntry.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<HistoricalTicksRequest_MiscOptionsEntry>): HistoricalTicksRequest_MiscOptionsEntry {
    const message = createBaseHistoricalTicksRequest_MiscOptionsEntry();
    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;
}
