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

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

export const protobufPackage = "protobuf";

export interface RealTimeBarTick {
  reqId?: number | undefined;
  time?: number | undefined;
  open?: number | undefined;
  high?: number | undefined;
  low?: number | undefined;
  close?: number | undefined;
  volume?: string | undefined;
  WAP?: string | undefined;
  count?: number | undefined;
}

function createBaseRealTimeBarTick(): RealTimeBarTick {
  return {
    reqId: undefined,
    time: undefined,
    open: undefined,
    high: undefined,
    low: undefined,
    close: undefined,
    volume: undefined,
    WAP: undefined,
    count: undefined,
  };
}

export const RealTimeBarTick: MessageFns<RealTimeBarTick> = {
  encode(message: RealTimeBarTick, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.reqId !== undefined) {
      writer.uint32(8).int32(message.reqId);
    }
    if (message.time !== undefined) {
      writer.uint32(16).int64(message.time);
    }
    if (message.open !== undefined) {
      writer.uint32(25).double(message.open);
    }
    if (message.high !== undefined) {
      writer.uint32(33).double(message.high);
    }
    if (message.low !== undefined) {
      writer.uint32(41).double(message.low);
    }
    if (message.close !== undefined) {
      writer.uint32(49).double(message.close);
    }
    if (message.volume !== undefined) {
      writer.uint32(58).string(message.volume);
    }
    if (message.WAP !== undefined) {
      writer.uint32(66).string(message.WAP);
    }
    if (message.count !== undefined) {
      writer.uint32(72).int32(message.count);
    }
    return writer;
  },

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

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

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

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

          message.low = reader.double();
          continue;
        }
        case 6: {
          if (tag !== 49) {
            break;
          }

          message.close = reader.double();
          continue;
        }
        case 7: {
          if (tag !== 58) {
            break;
          }

          message.volume = reader.string();
          continue;
        }
        case 8: {
          if (tag !== 66) {
            break;
          }

          message.WAP = reader.string();
          continue;
        }
        case 9: {
          if (tag !== 72) {
            break;
          }

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

  fromJSON(object: any): RealTimeBarTick {
    return {
      reqId: isSet(object.reqId) ? globalThis.Number(object.reqId) : undefined,
      time: isSet(object.time) ? globalThis.Number(object.time) : undefined,
      open: isSet(object.open) ? globalThis.Number(object.open) : undefined,
      high: isSet(object.high) ? globalThis.Number(object.high) : undefined,
      low: isSet(object.low) ? globalThis.Number(object.low) : undefined,
      close: isSet(object.close) ? globalThis.Number(object.close) : undefined,
      volume: isSet(object.volume) ? globalThis.String(object.volume) : undefined,
      WAP: isSet(object.WAP) ? globalThis.String(object.WAP) : undefined,
      count: isSet(object.count) ? globalThis.Number(object.count) : undefined,
    };
  },

  toJSON(message: RealTimeBarTick): unknown {
    const obj: any = {};
    if (message.reqId !== undefined) {
      obj.reqId = Math.round(message.reqId);
    }
    if (message.time !== undefined) {
      obj.time = Math.round(message.time);
    }
    if (message.open !== undefined) {
      obj.open = message.open;
    }
    if (message.high !== undefined) {
      obj.high = message.high;
    }
    if (message.low !== undefined) {
      obj.low = message.low;
    }
    if (message.close !== undefined) {
      obj.close = message.close;
    }
    if (message.volume !== undefined) {
      obj.volume = message.volume;
    }
    if (message.WAP !== undefined) {
      obj.WAP = message.WAP;
    }
    if (message.count !== undefined) {
      obj.count = Math.round(message.count);
    }
    return obj;
  },

  create(base?: DeepPartial<RealTimeBarTick>): RealTimeBarTick {
    return RealTimeBarTick.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<RealTimeBarTick>): RealTimeBarTick {
    const message = createBaseRealTimeBarTick();
    message.reqId = object.reqId ?? undefined;
    message.time = object.time ?? undefined;
    message.open = object.open ?? undefined;
    message.high = object.high ?? undefined;
    message.low = object.low ?? undefined;
    message.close = object.close ?? undefined;
    message.volume = object.volume ?? undefined;
    message.WAP = object.WAP ?? undefined;
    message.count = object.count ?? 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;
}
