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

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

export const protobufPackage = "protobuf";

export interface HistoricalNewsRequest {
  reqId?: number | undefined;
  conId?: number | undefined;
  providerCodes?: string | undefined;
  startDateTime?: string | undefined;
  endDateTime?: string | undefined;
  totalResults?: number | undefined;
  historicalNewsOptions: { [key: string]: string };
}

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

function createBaseHistoricalNewsRequest(): HistoricalNewsRequest {
  return {
    reqId: undefined,
    conId: undefined,
    providerCodes: undefined,
    startDateTime: undefined,
    endDateTime: undefined,
    totalResults: undefined,
    historicalNewsOptions: {},
  };
}

export const HistoricalNewsRequest: MessageFns<HistoricalNewsRequest> = {
  encode(message: HistoricalNewsRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.reqId !== undefined) {
      writer.uint32(8).int32(message.reqId);
    }
    if (message.conId !== undefined) {
      writer.uint32(16).int32(message.conId);
    }
    if (message.providerCodes !== undefined) {
      writer.uint32(26).string(message.providerCodes);
    }
    if (message.startDateTime !== undefined) {
      writer.uint32(34).string(message.startDateTime);
    }
    if (message.endDateTime !== undefined) {
      writer.uint32(42).string(message.endDateTime);
    }
    if (message.totalResults !== undefined) {
      writer.uint32(48).int32(message.totalResults);
    }
    globalThis.Object.entries(message.historicalNewsOptions).forEach(([key, value]: [string, string]) => {
      HistoricalNewsRequest_HistoricalNewsOptionsEntry.encode({ key: key as any, value }, writer.uint32(58).fork())
        .join();
    });
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): HistoricalNewsRequest {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseHistoricalNewsRequest();
    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.conId = reader.int32();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

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

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

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

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

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

  fromJSON(object: any): HistoricalNewsRequest {
    return {
      reqId: isSet(object.reqId) ? globalThis.Number(object.reqId) : undefined,
      conId: isSet(object.conId) ? globalThis.Number(object.conId) : undefined,
      providerCodes: isSet(object.providerCodes) ? globalThis.String(object.providerCodes) : undefined,
      startDateTime: isSet(object.startDateTime) ? globalThis.String(object.startDateTime) : undefined,
      endDateTime: isSet(object.endDateTime) ? globalThis.String(object.endDateTime) : undefined,
      totalResults: isSet(object.totalResults) ? globalThis.Number(object.totalResults) : undefined,
      historicalNewsOptions: isObject(object.historicalNewsOptions)
        ? (globalThis.Object.entries(object.historicalNewsOptions) as [string, any][]).reduce(
          (acc: { [key: string]: string }, [key, value]: [string, any]) => {
            acc[key] = globalThis.String(value);
            return acc;
          },
          {},
        )
        : {},
    };
  },

  toJSON(message: HistoricalNewsRequest): unknown {
    const obj: any = {};
    if (message.reqId !== undefined) {
      obj.reqId = Math.round(message.reqId);
    }
    if (message.conId !== undefined) {
      obj.conId = Math.round(message.conId);
    }
    if (message.providerCodes !== undefined) {
      obj.providerCodes = message.providerCodes;
    }
    if (message.startDateTime !== undefined) {
      obj.startDateTime = message.startDateTime;
    }
    if (message.endDateTime !== undefined) {
      obj.endDateTime = message.endDateTime;
    }
    if (message.totalResults !== undefined) {
      obj.totalResults = Math.round(message.totalResults);
    }
    if (message.historicalNewsOptions) {
      const entries = globalThis.Object.entries(message.historicalNewsOptions) as [string, string][];
      if (entries.length > 0) {
        obj.historicalNewsOptions = {};
        entries.forEach(([k, v]) => {
          obj.historicalNewsOptions[k] = v;
        });
      }
    }
    return obj;
  },

  create(base?: DeepPartial<HistoricalNewsRequest>): HistoricalNewsRequest {
    return HistoricalNewsRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<HistoricalNewsRequest>): HistoricalNewsRequest {
    const message = createBaseHistoricalNewsRequest();
    message.reqId = object.reqId ?? undefined;
    message.conId = object.conId ?? undefined;
    message.providerCodes = object.providerCodes ?? undefined;
    message.startDateTime = object.startDateTime ?? undefined;
    message.endDateTime = object.endDateTime ?? undefined;
    message.totalResults = object.totalResults ?? undefined;
    message.historicalNewsOptions =
      (globalThis.Object.entries(object.historicalNewsOptions ?? {}) 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 createBaseHistoricalNewsRequest_HistoricalNewsOptionsEntry(): HistoricalNewsRequest_HistoricalNewsOptionsEntry {
  return { key: "", value: "" };
}

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

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

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