// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.11.6
//   protoc               v3.19.1
// source: events/events.proto

/* eslint-disable */
import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
import type { CallContext, CallOptions } from 'nice-grpc-common';
import { Timestamp } from '../google/protobuf/timestamp';

export const protobufPackage = '';

export interface Event {
  /** the tenant id */
  tenantId: string;
  /** the id of the event */
  eventId: string;
  /** the key for the event */
  key: string;
  /** the payload for the event */
  payload: string;
  /** when the event was generated */
  eventTimestamp: Date | undefined;
  /** the additional metadata for the event */
  additionalMetadata?: string | undefined;
  /** the scope associated with this filter. Used for subsetting candidate filters at evaluation time */
  scope?: string | undefined;
}

export interface Events {
  events: Event[];
}

export interface PutLogRequest {
  /** the task external run id for the request */
  taskRunExternalId: string;
  /** when the log line was created */
  createdAt: Date | undefined;
  /** the log line message */
  message: string;
  /** the log line level */
  level?: string | undefined;
  /** associated log line metadata */
  metadata: string;
  /** the retry count of the task run */
  taskRetryCount?: number | undefined;
}

export interface PutLogResponse {}

export interface PutStreamEventRequest {
  /** the task external run id for the request */
  taskRunExternalId: string;
  /** when the stream event was created */
  createdAt: Date | undefined;
  /** the stream event message */
  message: Uint8Array;
  /** associated stream event metadata */
  metadata: string;
  eventIndex?: number | undefined;
}

export interface PutStreamEventResponse {}

export interface BulkPushEventRequest {
  events: PushEventRequest[];
}

export interface PushEventRequest {
  /** the key for the event */
  key: string;
  /** the payload for the event */
  payload: string;
  /** when the event was generated */
  eventTimestamp: Date | undefined;
  /** metadata for the event */
  additionalMetadata?: string | undefined;
  priority?: number | undefined;
  /** the scope associated with this filter. Used for subsetting candidate filters at evaluation time */
  scope?: string | undefined;
}

export interface ReplayEventRequest {
  /** the event id to replay */
  eventId: string;
}

function createBaseEvent(): Event {
  return {
    tenantId: '',
    eventId: '',
    key: '',
    payload: '',
    eventTimestamp: undefined,
    additionalMetadata: undefined,
    scope: undefined,
  };
}

export const Event: MessageFns<Event> = {
  encode(message: Event, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.tenantId !== '') {
      writer.uint32(10).string(message.tenantId);
    }
    if (message.eventId !== '') {
      writer.uint32(18).string(message.eventId);
    }
    if (message.key !== '') {
      writer.uint32(26).string(message.key);
    }
    if (message.payload !== '') {
      writer.uint32(34).string(message.payload);
    }
    if (message.eventTimestamp !== undefined) {
      Timestamp.encode(toTimestamp(message.eventTimestamp), writer.uint32(42).fork()).join();
    }
    if (message.additionalMetadata !== undefined) {
      writer.uint32(50).string(message.additionalMetadata);
    }
    if (message.scope !== undefined) {
      writer.uint32(58).string(message.scope);
    }
    return writer;
  },

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

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

          message.eventId = reader.string();
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

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

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

          message.eventTimestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
        case 6: {
          if (tag !== 50) {
            break;
          }

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

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

  fromJSON(object: any): Event {
    return {
      tenantId: isSet(object.tenantId)
        ? globalThis.String(object.tenantId)
        : isSet(object.tenant_id)
          ? globalThis.String(object.tenant_id)
          : '',
      eventId: isSet(object.eventId)
        ? globalThis.String(object.eventId)
        : isSet(object.event_id)
          ? globalThis.String(object.event_id)
          : '',
      key: isSet(object.key) ? globalThis.String(object.key) : '',
      payload: isSet(object.payload) ? globalThis.String(object.payload) : '',
      eventTimestamp: isSet(object.eventTimestamp)
        ? fromJsonTimestamp(object.eventTimestamp)
        : isSet(object.event_timestamp)
          ? fromJsonTimestamp(object.event_timestamp)
          : undefined,
      additionalMetadata: isSet(object.additionalMetadata)
        ? globalThis.String(object.additionalMetadata)
        : isSet(object.additional_metadata)
          ? globalThis.String(object.additional_metadata)
          : undefined,
      scope: isSet(object.scope) ? globalThis.String(object.scope) : undefined,
    };
  },

  toJSON(message: Event): unknown {
    const obj: any = {};
    if (message.tenantId !== '') {
      obj.tenantId = message.tenantId;
    }
    if (message.eventId !== '') {
      obj.eventId = message.eventId;
    }
    if (message.key !== '') {
      obj.key = message.key;
    }
    if (message.payload !== '') {
      obj.payload = message.payload;
    }
    if (message.eventTimestamp !== undefined) {
      obj.eventTimestamp = message.eventTimestamp.toISOString();
    }
    if (message.additionalMetadata !== undefined) {
      obj.additionalMetadata = message.additionalMetadata;
    }
    if (message.scope !== undefined) {
      obj.scope = message.scope;
    }
    return obj;
  },

  create(base?: DeepPartial<Event>): Event {
    return Event.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<Event>): Event {
    const message = createBaseEvent();
    message.tenantId = object.tenantId ?? '';
    message.eventId = object.eventId ?? '';
    message.key = object.key ?? '';
    message.payload = object.payload ?? '';
    message.eventTimestamp = object.eventTimestamp ?? undefined;
    message.additionalMetadata = object.additionalMetadata ?? undefined;
    message.scope = object.scope ?? undefined;
    return message;
  },
};

function createBaseEvents(): Events {
  return { events: [] };
}

export const Events: MessageFns<Events> = {
  encode(message: Events, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    for (const v of message.events) {
      Event.encode(v!, writer.uint32(10).fork()).join();
    }
    return writer;
  },

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

          message.events.push(Event.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): Events {
    return {
      events: globalThis.Array.isArray(object?.events)
        ? object.events.map((e: any) => Event.fromJSON(e))
        : [],
    };
  },

  toJSON(message: Events): unknown {
    const obj: any = {};
    if (message.events?.length) {
      obj.events = message.events.map((e) => Event.toJSON(e));
    }
    return obj;
  },

  create(base?: DeepPartial<Events>): Events {
    return Events.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<Events>): Events {
    const message = createBaseEvents();
    message.events = object.events?.map((e) => Event.fromPartial(e)) || [];
    return message;
  },
};

function createBasePutLogRequest(): PutLogRequest {
  return {
    taskRunExternalId: '',
    createdAt: undefined,
    message: '',
    level: undefined,
    metadata: '',
    taskRetryCount: undefined,
  };
}

export const PutLogRequest: MessageFns<PutLogRequest> = {
  encode(message: PutLogRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.taskRunExternalId !== '') {
      writer.uint32(10).string(message.taskRunExternalId);
    }
    if (message.createdAt !== undefined) {
      Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(18).fork()).join();
    }
    if (message.message !== '') {
      writer.uint32(26).string(message.message);
    }
    if (message.level !== undefined) {
      writer.uint32(34).string(message.level);
    }
    if (message.metadata !== '') {
      writer.uint32(42).string(message.metadata);
    }
    if (message.taskRetryCount !== undefined) {
      writer.uint32(48).int32(message.taskRetryCount);
    }
    return writer;
  },

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

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

          message.createdAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

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

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

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

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

  fromJSON(object: any): PutLogRequest {
    return {
      taskRunExternalId: isSet(object.taskRunExternalId)
        ? globalThis.String(object.taskRunExternalId)
        : isSet(object.task_run_external_id)
          ? globalThis.String(object.task_run_external_id)
          : '',
      createdAt: isSet(object.createdAt)
        ? fromJsonTimestamp(object.createdAt)
        : isSet(object.created_at)
          ? fromJsonTimestamp(object.created_at)
          : undefined,
      message: isSet(object.message) ? globalThis.String(object.message) : '',
      level: isSet(object.level) ? globalThis.String(object.level) : undefined,
      metadata: isSet(object.metadata) ? globalThis.String(object.metadata) : '',
      taskRetryCount: isSet(object.taskRetryCount)
        ? globalThis.Number(object.taskRetryCount)
        : isSet(object.task_retry_count)
          ? globalThis.Number(object.task_retry_count)
          : undefined,
    };
  },

  toJSON(message: PutLogRequest): unknown {
    const obj: any = {};
    if (message.taskRunExternalId !== '') {
      obj.taskRunExternalId = message.taskRunExternalId;
    }
    if (message.createdAt !== undefined) {
      obj.createdAt = message.createdAt.toISOString();
    }
    if (message.message !== '') {
      obj.message = message.message;
    }
    if (message.level !== undefined) {
      obj.level = message.level;
    }
    if (message.metadata !== '') {
      obj.metadata = message.metadata;
    }
    if (message.taskRetryCount !== undefined) {
      obj.taskRetryCount = Math.round(message.taskRetryCount);
    }
    return obj;
  },

  create(base?: DeepPartial<PutLogRequest>): PutLogRequest {
    return PutLogRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<PutLogRequest>): PutLogRequest {
    const message = createBasePutLogRequest();
    message.taskRunExternalId = object.taskRunExternalId ?? '';
    message.createdAt = object.createdAt ?? undefined;
    message.message = object.message ?? '';
    message.level = object.level ?? undefined;
    message.metadata = object.metadata ?? '';
    message.taskRetryCount = object.taskRetryCount ?? undefined;
    return message;
  },
};

function createBasePutLogResponse(): PutLogResponse {
  return {};
}

export const PutLogResponse: MessageFns<PutLogResponse> = {
  encode(_: PutLogResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PutLogResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePutLogResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): PutLogResponse {
    return {};
  },

  toJSON(_: PutLogResponse): unknown {
    const obj: any = {};
    return obj;
  },

  create(base?: DeepPartial<PutLogResponse>): PutLogResponse {
    return PutLogResponse.fromPartial(base ?? {});
  },
  fromPartial(_: DeepPartial<PutLogResponse>): PutLogResponse {
    const message = createBasePutLogResponse();
    return message;
  },
};

function createBasePutStreamEventRequest(): PutStreamEventRequest {
  return {
    taskRunExternalId: '',
    createdAt: undefined,
    message: new Uint8Array(0),
    metadata: '',
    eventIndex: undefined,
  };
}

export const PutStreamEventRequest: MessageFns<PutStreamEventRequest> = {
  encode(message: PutStreamEventRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.taskRunExternalId !== '') {
      writer.uint32(10).string(message.taskRunExternalId);
    }
    if (message.createdAt !== undefined) {
      Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(18).fork()).join();
    }
    if (message.message.length !== 0) {
      writer.uint32(26).bytes(message.message);
    }
    if (message.metadata !== '') {
      writer.uint32(42).string(message.metadata);
    }
    if (message.eventIndex !== undefined) {
      writer.uint32(48).int64(message.eventIndex);
    }
    return writer;
  },

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

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

          message.createdAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

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

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

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

  fromJSON(object: any): PutStreamEventRequest {
    return {
      taskRunExternalId: isSet(object.taskRunExternalId)
        ? globalThis.String(object.taskRunExternalId)
        : isSet(object.task_run_external_id)
          ? globalThis.String(object.task_run_external_id)
          : '',
      createdAt: isSet(object.createdAt)
        ? fromJsonTimestamp(object.createdAt)
        : isSet(object.created_at)
          ? fromJsonTimestamp(object.created_at)
          : undefined,
      message: isSet(object.message) ? bytesFromBase64(object.message) : new Uint8Array(0),
      metadata: isSet(object.metadata) ? globalThis.String(object.metadata) : '',
      eventIndex: isSet(object.eventIndex)
        ? globalThis.Number(object.eventIndex)
        : isSet(object.event_index)
          ? globalThis.Number(object.event_index)
          : undefined,
    };
  },

  toJSON(message: PutStreamEventRequest): unknown {
    const obj: any = {};
    if (message.taskRunExternalId !== '') {
      obj.taskRunExternalId = message.taskRunExternalId;
    }
    if (message.createdAt !== undefined) {
      obj.createdAt = message.createdAt.toISOString();
    }
    if (message.message.length !== 0) {
      obj.message = base64FromBytes(message.message);
    }
    if (message.metadata !== '') {
      obj.metadata = message.metadata;
    }
    if (message.eventIndex !== undefined) {
      obj.eventIndex = Math.round(message.eventIndex);
    }
    return obj;
  },

  create(base?: DeepPartial<PutStreamEventRequest>): PutStreamEventRequest {
    return PutStreamEventRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<PutStreamEventRequest>): PutStreamEventRequest {
    const message = createBasePutStreamEventRequest();
    message.taskRunExternalId = object.taskRunExternalId ?? '';
    message.createdAt = object.createdAt ?? undefined;
    message.message = object.message ?? new Uint8Array(0);
    message.metadata = object.metadata ?? '';
    message.eventIndex = object.eventIndex ?? undefined;
    return message;
  },
};

function createBasePutStreamEventResponse(): PutStreamEventResponse {
  return {};
}

export const PutStreamEventResponse: MessageFns<PutStreamEventResponse> = {
  encode(_: PutStreamEventResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    return writer;
  },

  decode(input: BinaryReader | Uint8Array, length?: number): PutStreamEventResponse {
    const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
    const end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePutStreamEventResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(_: any): PutStreamEventResponse {
    return {};
  },

  toJSON(_: PutStreamEventResponse): unknown {
    const obj: any = {};
    return obj;
  },

  create(base?: DeepPartial<PutStreamEventResponse>): PutStreamEventResponse {
    return PutStreamEventResponse.fromPartial(base ?? {});
  },
  fromPartial(_: DeepPartial<PutStreamEventResponse>): PutStreamEventResponse {
    const message = createBasePutStreamEventResponse();
    return message;
  },
};

function createBaseBulkPushEventRequest(): BulkPushEventRequest {
  return { events: [] };
}

export const BulkPushEventRequest: MessageFns<BulkPushEventRequest> = {
  encode(message: BulkPushEventRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    for (const v of message.events) {
      PushEventRequest.encode(v!, writer.uint32(10).fork()).join();
    }
    return writer;
  },

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

          message.events.push(PushEventRequest.decode(reader, reader.uint32()));
          continue;
        }
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skip(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): BulkPushEventRequest {
    return {
      events: globalThis.Array.isArray(object?.events)
        ? object.events.map((e: any) => PushEventRequest.fromJSON(e))
        : [],
    };
  },

  toJSON(message: BulkPushEventRequest): unknown {
    const obj: any = {};
    if (message.events?.length) {
      obj.events = message.events.map((e) => PushEventRequest.toJSON(e));
    }
    return obj;
  },

  create(base?: DeepPartial<BulkPushEventRequest>): BulkPushEventRequest {
    return BulkPushEventRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<BulkPushEventRequest>): BulkPushEventRequest {
    const message = createBaseBulkPushEventRequest();
    message.events = object.events?.map((e) => PushEventRequest.fromPartial(e)) || [];
    return message;
  },
};

function createBasePushEventRequest(): PushEventRequest {
  return {
    key: '',
    payload: '',
    eventTimestamp: undefined,
    additionalMetadata: undefined,
    priority: undefined,
    scope: undefined,
  };
}

export const PushEventRequest: MessageFns<PushEventRequest> = {
  encode(message: PushEventRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.key !== '') {
      writer.uint32(10).string(message.key);
    }
    if (message.payload !== '') {
      writer.uint32(18).string(message.payload);
    }
    if (message.eventTimestamp !== undefined) {
      Timestamp.encode(toTimestamp(message.eventTimestamp), writer.uint32(26).fork()).join();
    }
    if (message.additionalMetadata !== undefined) {
      writer.uint32(34).string(message.additionalMetadata);
    }
    if (message.priority !== undefined) {
      writer.uint32(40).int32(message.priority);
    }
    if (message.scope !== undefined) {
      writer.uint32(50).string(message.scope);
    }
    return writer;
  },

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

          message.eventTimestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        }
        case 4: {
          if (tag !== 34) {
            break;
          }

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

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

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

  fromJSON(object: any): PushEventRequest {
    return {
      key: isSet(object.key) ? globalThis.String(object.key) : '',
      payload: isSet(object.payload) ? globalThis.String(object.payload) : '',
      eventTimestamp: isSet(object.eventTimestamp)
        ? fromJsonTimestamp(object.eventTimestamp)
        : isSet(object.event_timestamp)
          ? fromJsonTimestamp(object.event_timestamp)
          : undefined,
      additionalMetadata: isSet(object.additionalMetadata)
        ? globalThis.String(object.additionalMetadata)
        : isSet(object.additional_metadata)
          ? globalThis.String(object.additional_metadata)
          : undefined,
      priority: isSet(object.priority) ? globalThis.Number(object.priority) : undefined,
      scope: isSet(object.scope) ? globalThis.String(object.scope) : undefined,
    };
  },

  toJSON(message: PushEventRequest): unknown {
    const obj: any = {};
    if (message.key !== '') {
      obj.key = message.key;
    }
    if (message.payload !== '') {
      obj.payload = message.payload;
    }
    if (message.eventTimestamp !== undefined) {
      obj.eventTimestamp = message.eventTimestamp.toISOString();
    }
    if (message.additionalMetadata !== undefined) {
      obj.additionalMetadata = message.additionalMetadata;
    }
    if (message.priority !== undefined) {
      obj.priority = Math.round(message.priority);
    }
    if (message.scope !== undefined) {
      obj.scope = message.scope;
    }
    return obj;
  },

  create(base?: DeepPartial<PushEventRequest>): PushEventRequest {
    return PushEventRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<PushEventRequest>): PushEventRequest {
    const message = createBasePushEventRequest();
    message.key = object.key ?? '';
    message.payload = object.payload ?? '';
    message.eventTimestamp = object.eventTimestamp ?? undefined;
    message.additionalMetadata = object.additionalMetadata ?? undefined;
    message.priority = object.priority ?? undefined;
    message.scope = object.scope ?? undefined;
    return message;
  },
};

function createBaseReplayEventRequest(): ReplayEventRequest {
  return { eventId: '' };
}

export const ReplayEventRequest: MessageFns<ReplayEventRequest> = {
  encode(message: ReplayEventRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.eventId !== '') {
      writer.uint32(10).string(message.eventId);
    }
    return writer;
  },

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

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

  fromJSON(object: any): ReplayEventRequest {
    return {
      eventId: isSet(object.eventId)
        ? globalThis.String(object.eventId)
        : isSet(object.event_id)
          ? globalThis.String(object.event_id)
          : '',
    };
  },

  toJSON(message: ReplayEventRequest): unknown {
    const obj: any = {};
    if (message.eventId !== '') {
      obj.eventId = message.eventId;
    }
    return obj;
  },

  create(base?: DeepPartial<ReplayEventRequest>): ReplayEventRequest {
    return ReplayEventRequest.fromPartial(base ?? {});
  },
  fromPartial(object: DeepPartial<ReplayEventRequest>): ReplayEventRequest {
    const message = createBaseReplayEventRequest();
    message.eventId = object.eventId ?? '';
    return message;
  },
};

export type EventsServiceDefinition = typeof EventsServiceDefinition;
export const EventsServiceDefinition = {
  name: 'EventsService',
  fullName: 'EventsService',
  methods: {
    push: {
      name: 'Push',
      requestType: PushEventRequest as typeof PushEventRequest,
      requestStream: false,
      responseType: Event as typeof Event,
      responseStream: false,
      options: {},
    },
    bulkPush: {
      name: 'BulkPush',
      requestType: BulkPushEventRequest as typeof BulkPushEventRequest,
      requestStream: false,
      responseType: Events as typeof Events,
      responseStream: false,
      options: {},
    },
    replaySingleEvent: {
      name: 'ReplaySingleEvent',
      requestType: ReplayEventRequest as typeof ReplayEventRequest,
      requestStream: false,
      responseType: Event as typeof Event,
      responseStream: false,
      options: {},
    },
    putLog: {
      name: 'PutLog',
      requestType: PutLogRequest as typeof PutLogRequest,
      requestStream: false,
      responseType: PutLogResponse as typeof PutLogResponse,
      responseStream: false,
      options: {},
    },
    putStreamEvent: {
      name: 'PutStreamEvent',
      requestType: PutStreamEventRequest as typeof PutStreamEventRequest,
      requestStream: false,
      responseType: PutStreamEventResponse as typeof PutStreamEventResponse,
      responseStream: false,
      options: {},
    },
  },
} as const;

export interface EventsServiceImplementation<CallContextExt = {}> {
  push(
    request: PushEventRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<Event>>;
  bulkPush(
    request: BulkPushEventRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<Events>>;
  replaySingleEvent(
    request: ReplayEventRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<Event>>;
  putLog(
    request: PutLogRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<PutLogResponse>>;
  putStreamEvent(
    request: PutStreamEventRequest,
    context: CallContext & CallContextExt
  ): Promise<DeepPartial<PutStreamEventResponse>>;
}

export interface EventsServiceClient<CallOptionsExt = {}> {
  push(
    request: DeepPartial<PushEventRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<Event>;
  bulkPush(
    request: DeepPartial<BulkPushEventRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<Events>;
  replaySingleEvent(
    request: DeepPartial<ReplayEventRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<Event>;
  putLog(
    request: DeepPartial<PutLogRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<PutLogResponse>;
  putStreamEvent(
    request: DeepPartial<PutStreamEventRequest>,
    options?: CallOptions & CallOptionsExt
  ): Promise<PutStreamEventResponse>;
}

function bytesFromBase64(b64: string): Uint8Array {
  if ((globalThis as any).Buffer) {
    return Uint8Array.from((globalThis as any).Buffer.from(b64, 'base64'));
  } else {
    const bin = globalThis.atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
      arr[i] = bin.charCodeAt(i);
    }
    return arr;
  }
}

function base64FromBytes(arr: Uint8Array): string {
  if ((globalThis as any).Buffer) {
    return (globalThis as any).Buffer.from(arr).toString('base64');
  } else {
    const bin: string[] = [];
    arr.forEach((byte) => {
      bin.push(globalThis.String.fromCharCode(byte));
    });
    return globalThis.btoa(bin.join(''));
  }
}

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 toTimestamp(date: Date): Timestamp {
  const seconds = Math.trunc(date.getTime() / 1_000);
  const nanos = (date.getTime() % 1_000) * 1_000_000;
  return { seconds, nanos };
}

function fromTimestamp(t: Timestamp): Date {
  let millis = (t.seconds || 0) * 1_000;
  millis += (t.nanos || 0) / 1_000_000;
  return new globalThis.Date(millis);
}

function fromJsonTimestamp(o: any): Date {
  if (o instanceof globalThis.Date) {
    return o;
  } else if (typeof o === 'string') {
    return new globalThis.Date(o);
  } else {
    return fromTimestamp(Timestamp.fromJSON(o));
  }
}

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