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

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

export const protobufPackage = "protobuf";

export interface HistoricalTickBidAsk {
  time?: number | undefined;
  tickAttribBidAsk?: TickAttribBidAsk | undefined;
  priceBid?: number | undefined;
  priceAsk?: number | undefined;
  sizeBid?: string | undefined;
  sizeAsk?: string | undefined;
}

function createBaseHistoricalTickBidAsk(): HistoricalTickBidAsk {
  return {
    time: undefined,
    tickAttribBidAsk: undefined,
    priceBid: undefined,
    priceAsk: undefined,
    sizeBid: undefined,
    sizeAsk: undefined,
  };
}

export const HistoricalTickBidAsk: MessageFns<HistoricalTickBidAsk> = {
  encode(message: HistoricalTickBidAsk, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.time !== undefined) {
      writer.uint32(8).int64(message.time);
    }
    if (message.tickAttribBidAsk !== undefined) {
      TickAttribBidAsk.encode(message.tickAttribBidAsk, writer.uint32(18).fork()).join();
    }
    if (message.priceBid !== undefined) {
      writer.uint32(25).double(message.priceBid);
    }
    if (message.priceAsk !== undefined) {
      writer.uint32(33).double(message.priceAsk);
    }
    if (message.sizeBid !== undefined) {
      writer.uint32(42).string(message.sizeBid);
    }
    if (message.sizeAsk !== undefined) {
      writer.uint32(50).string(message.sizeAsk);
    }
    return writer;
  },

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

          message.time = longToNumber(reader.int64());
          continue;
        }
        case 2: {
          if (tag !== 18) {
            break;
          }

          message.tickAttribBidAsk = TickAttribBidAsk.decode(reader, reader.uint32());
          continue;
        }
        case 3: {
          if (tag !== 25) {
            break;
          }

          message.priceBid = reader.double();
          continue;
        }
        case 4: {
          if (tag !== 33) {
            break;
          }

          message.priceAsk = reader.double();
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

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

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

  fromJSON(object: any): HistoricalTickBidAsk {
    return {
      time: isSet(object.time) ? globalThis.Number(object.time) : undefined,
      tickAttribBidAsk: isSet(object.tickAttribBidAsk) ? TickAttribBidAsk.fromJSON(object.tickAttribBidAsk) : undefined,
      priceBid: isSet(object.priceBid) ? globalThis.Number(object.priceBid) : undefined,
      priceAsk: isSet(object.priceAsk) ? globalThis.Number(object.priceAsk) : undefined,
      sizeBid: isSet(object.sizeBid) ? globalThis.String(object.sizeBid) : undefined,
      sizeAsk: isSet(object.sizeAsk) ? globalThis.String(object.sizeAsk) : undefined,
    };
  },

  toJSON(message: HistoricalTickBidAsk): unknown {
    const obj: any = {};
    if (message.time !== undefined) {
      obj.time = Math.round(message.time);
    }
    if (message.tickAttribBidAsk !== undefined) {
      obj.tickAttribBidAsk = TickAttribBidAsk.toJSON(message.tickAttribBidAsk);
    }
    if (message.priceBid !== undefined) {
      obj.priceBid = message.priceBid;
    }
    if (message.priceAsk !== undefined) {
      obj.priceAsk = message.priceAsk;
    }
    if (message.sizeBid !== undefined) {
      obj.sizeBid = message.sizeBid;
    }
    if (message.sizeAsk !== undefined) {
      obj.sizeAsk = message.sizeAsk;
    }
    return obj;
  },

  create(base?: DeepPartial<HistoricalTickBidAsk>): HistoricalTickBidAsk {
    return HistoricalTickBidAsk.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<HistoricalTickBidAsk>): HistoricalTickBidAsk {
    const message = createBaseHistoricalTickBidAsk();
    message.time = object.time ?? undefined;
    message.tickAttribBidAsk = (object.tickAttribBidAsk !== undefined && object.tickAttribBidAsk !== null)
      ? TickAttribBidAsk.fromPartial(object.tickAttribBidAsk)
      : undefined;
    message.priceBid = object.priceBid ?? undefined;
    message.priceAsk = object.priceAsk ?? undefined;
    message.sizeBid = object.sizeBid ?? undefined;
    message.sizeAsk = object.sizeAsk ?? 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>;

function longToNumber(int64: { toString(): string }): number {
  const num = globalThis.Number(int64.toString());
  if (num > globalThis.Number.MAX_SAFE_INTEGER) {
    throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
  }
  if (num < globalThis.Number.MIN_SAFE_INTEGER) {
    throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
  }
  return num;
}

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;
}
