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

/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import {
  type CallOptions,
  type ChannelCredentials,
  Client,
  type ClientOptions,
  type ClientUnaryCall,
  type handleUnaryCall,
  makeGenericClientConstructor,
  type Metadata,
  type ServiceError,
  type UntypedServiceImplementation,
} from "@grpc/grpc-js";
import Long from "long";
import { AclSpec, Principal } from "./common";
import { Struct } from "./google/protobuf/struct";
import { Timestamp } from "./google/protobuf/timestamp";

export interface IngestChunk {
  content: string;
  metadata?: { [key: string]: any } | undefined;
  acl?: AclSpec | undefined;
}

export interface IngestDocumentRequest {
  source: string;
  externalId: string;
  title: string;
  chunks: IngestChunk[];
  principal?: Principal | undefined;
}

export interface IngestDocumentResponse {
  documentId: string;
  chunksIngested: number;
}

export interface GetDocumentRequest {
  id: string;
}

export interface DocumentSummary {
  id: string;
  sourceUri: string;
  title: string;
  externalId: string;
  ingestedAt?: Date | undefined;
  chunkCount: number;
}

export interface DeleteDocumentRequest {
  id: string;
}

export interface DeleteDocumentResponse {
  deleted: boolean;
}

function createBaseIngestChunk(): IngestChunk {
  return { content: "", metadata: undefined, acl: undefined };
}

export const IngestChunk: MessageFns<IngestChunk> = {
  encode(message: IngestChunk, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.content !== "") {
      writer.uint32(10).string(message.content);
    }
    if (message.metadata !== undefined) {
      Struct.encode(Struct.wrap(message.metadata), writer.uint32(18).fork()).join();
    }
    if (message.acl !== undefined) {
      AclSpec.encode(message.acl, writer.uint32(26).fork()).join();
    }
    return writer;
  },

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

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

          message.metadata = Struct.unwrap(Struct.decode(reader, reader.uint32()));
          continue;
        }
        case 3: {
          if (tag !== 26) {
            break;
          }

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

  fromJSON(object: any): IngestChunk {
    return {
      content: isSet(object.content) ? globalThis.String(object.content) : "",
      metadata: isObject(object.metadata) ? object.metadata : undefined,
      acl: isSet(object.acl) ? AclSpec.fromJSON(object.acl) : undefined,
    };
  },

  toJSON(message: IngestChunk): unknown {
    const obj: any = {};
    if (message.content !== "") {
      obj.content = message.content;
    }
    if (message.metadata !== undefined) {
      obj.metadata = message.metadata;
    }
    if (message.acl !== undefined) {
      obj.acl = AclSpec.toJSON(message.acl);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<IngestChunk>, I>>(base?: I): IngestChunk {
    return IngestChunk.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<IngestChunk>, I>>(object: I): IngestChunk {
    const message = createBaseIngestChunk();
    message.content = object.content ?? "";
    message.metadata = object.metadata ?? undefined;
    message.acl = (object.acl !== undefined && object.acl !== null) ? AclSpec.fromPartial(object.acl) : undefined;
    return message;
  },
};

function createBaseIngestDocumentRequest(): IngestDocumentRequest {
  return { source: "", externalId: "", title: "", chunks: [], principal: undefined };
}

export const IngestDocumentRequest: MessageFns<IngestDocumentRequest> = {
  encode(message: IngestDocumentRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.source !== "") {
      writer.uint32(10).string(message.source);
    }
    if (message.externalId !== "") {
      writer.uint32(18).string(message.externalId);
    }
    if (message.title !== "") {
      writer.uint32(26).string(message.title);
    }
    for (const v of message.chunks) {
      IngestChunk.encode(v!, writer.uint32(34).fork()).join();
    }
    if (message.principal !== undefined) {
      Principal.encode(message.principal, writer.uint32(42).fork()).join();
    }
    return writer;
  },

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

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

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

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

          message.chunks.push(IngestChunk.decode(reader, reader.uint32()));
          continue;
        }
        case 5: {
          if (tag !== 42) {
            break;
          }

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

  fromJSON(object: any): IngestDocumentRequest {
    return {
      source: isSet(object.source) ? globalThis.String(object.source) : "",
      externalId: isSet(object.externalId)
        ? globalThis.String(object.externalId)
        : isSet(object.external_id)
        ? globalThis.String(object.external_id)
        : "",
      title: isSet(object.title) ? globalThis.String(object.title) : "",
      chunks: globalThis.Array.isArray(object?.chunks) ? object.chunks.map((e: any) => IngestChunk.fromJSON(e)) : [],
      principal: isSet(object.principal) ? Principal.fromJSON(object.principal) : undefined,
    };
  },

  toJSON(message: IngestDocumentRequest): unknown {
    const obj: any = {};
    if (message.source !== "") {
      obj.source = message.source;
    }
    if (message.externalId !== "") {
      obj.externalId = message.externalId;
    }
    if (message.title !== "") {
      obj.title = message.title;
    }
    if (message.chunks?.length) {
      obj.chunks = message.chunks.map((e) => IngestChunk.toJSON(e));
    }
    if (message.principal !== undefined) {
      obj.principal = Principal.toJSON(message.principal);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<IngestDocumentRequest>, I>>(base?: I): IngestDocumentRequest {
    return IngestDocumentRequest.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<IngestDocumentRequest>, I>>(object: I): IngestDocumentRequest {
    const message = createBaseIngestDocumentRequest();
    message.source = object.source ?? "";
    message.externalId = object.externalId ?? "";
    message.title = object.title ?? "";
    message.chunks = object.chunks?.map((e) => IngestChunk.fromPartial(e)) || [];
    message.principal = (object.principal !== undefined && object.principal !== null)
      ? Principal.fromPartial(object.principal)
      : undefined;
    return message;
  },
};

function createBaseIngestDocumentResponse(): IngestDocumentResponse {
  return { documentId: "", chunksIngested: 0 };
}

export const IngestDocumentResponse: MessageFns<IngestDocumentResponse> = {
  encode(message: IngestDocumentResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.documentId !== "") {
      writer.uint32(10).string(message.documentId);
    }
    if (message.chunksIngested !== 0) {
      writer.uint32(16).int32(message.chunksIngested);
    }
    return writer;
  },

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

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

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

  fromJSON(object: any): IngestDocumentResponse {
    return {
      documentId: isSet(object.documentId)
        ? globalThis.String(object.documentId)
        : isSet(object.document_id)
        ? globalThis.String(object.document_id)
        : "",
      chunksIngested: isSet(object.chunksIngested)
        ? globalThis.Number(object.chunksIngested)
        : isSet(object.chunks_ingested)
        ? globalThis.Number(object.chunks_ingested)
        : 0,
    };
  },

  toJSON(message: IngestDocumentResponse): unknown {
    const obj: any = {};
    if (message.documentId !== "") {
      obj.documentId = message.documentId;
    }
    if (message.chunksIngested !== 0) {
      obj.chunksIngested = Math.round(message.chunksIngested);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<IngestDocumentResponse>, I>>(base?: I): IngestDocumentResponse {
    return IngestDocumentResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<IngestDocumentResponse>, I>>(object: I): IngestDocumentResponse {
    const message = createBaseIngestDocumentResponse();
    message.documentId = object.documentId ?? "";
    message.chunksIngested = object.chunksIngested ?? 0;
    return message;
  },
};

function createBaseGetDocumentRequest(): GetDocumentRequest {
  return { id: "" };
}

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

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

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

  fromJSON(object: any): GetDocumentRequest {
    return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
  },

  toJSON(message: GetDocumentRequest): unknown {
    const obj: any = {};
    if (message.id !== "") {
      obj.id = message.id;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<GetDocumentRequest>, I>>(base?: I): GetDocumentRequest {
    return GetDocumentRequest.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<GetDocumentRequest>, I>>(object: I): GetDocumentRequest {
    const message = createBaseGetDocumentRequest();
    message.id = object.id ?? "";
    return message;
  },
};

function createBaseDocumentSummary(): DocumentSummary {
  return { id: "", sourceUri: "", title: "", externalId: "", ingestedAt: undefined, chunkCount: 0 };
}

export const DocumentSummary: MessageFns<DocumentSummary> = {
  encode(message: DocumentSummary, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.id !== "") {
      writer.uint32(10).string(message.id);
    }
    if (message.sourceUri !== "") {
      writer.uint32(18).string(message.sourceUri);
    }
    if (message.title !== "") {
      writer.uint32(26).string(message.title);
    }
    if (message.externalId !== "") {
      writer.uint32(34).string(message.externalId);
    }
    if (message.ingestedAt !== undefined) {
      Timestamp.encode(toTimestamp(message.ingestedAt), writer.uint32(42).fork()).join();
    }
    if (message.chunkCount !== 0) {
      writer.uint32(48).int32(message.chunkCount);
    }
    return writer;
  },

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

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

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

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

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

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

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

  fromJSON(object: any): DocumentSummary {
    return {
      id: isSet(object.id) ? globalThis.String(object.id) : "",
      sourceUri: isSet(object.sourceUri)
        ? globalThis.String(object.sourceUri)
        : isSet(object.source_uri)
        ? globalThis.String(object.source_uri)
        : "",
      title: isSet(object.title) ? globalThis.String(object.title) : "",
      externalId: isSet(object.externalId)
        ? globalThis.String(object.externalId)
        : isSet(object.external_id)
        ? globalThis.String(object.external_id)
        : "",
      ingestedAt: isSet(object.ingestedAt)
        ? fromJsonTimestamp(object.ingestedAt)
        : isSet(object.ingested_at)
        ? fromJsonTimestamp(object.ingested_at)
        : undefined,
      chunkCount: isSet(object.chunkCount)
        ? globalThis.Number(object.chunkCount)
        : isSet(object.chunk_count)
        ? globalThis.Number(object.chunk_count)
        : 0,
    };
  },

  toJSON(message: DocumentSummary): unknown {
    const obj: any = {};
    if (message.id !== "") {
      obj.id = message.id;
    }
    if (message.sourceUri !== "") {
      obj.sourceUri = message.sourceUri;
    }
    if (message.title !== "") {
      obj.title = message.title;
    }
    if (message.externalId !== "") {
      obj.externalId = message.externalId;
    }
    if (message.ingestedAt !== undefined) {
      obj.ingestedAt = message.ingestedAt.toISOString();
    }
    if (message.chunkCount !== 0) {
      obj.chunkCount = Math.round(message.chunkCount);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<DocumentSummary>, I>>(base?: I): DocumentSummary {
    return DocumentSummary.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<DocumentSummary>, I>>(object: I): DocumentSummary {
    const message = createBaseDocumentSummary();
    message.id = object.id ?? "";
    message.sourceUri = object.sourceUri ?? "";
    message.title = object.title ?? "";
    message.externalId = object.externalId ?? "";
    message.ingestedAt = object.ingestedAt ?? undefined;
    message.chunkCount = object.chunkCount ?? 0;
    return message;
  },
};

function createBaseDeleteDocumentRequest(): DeleteDocumentRequest {
  return { id: "" };
}

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

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

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

  fromJSON(object: any): DeleteDocumentRequest {
    return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
  },

  toJSON(message: DeleteDocumentRequest): unknown {
    const obj: any = {};
    if (message.id !== "") {
      obj.id = message.id;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<DeleteDocumentRequest>, I>>(base?: I): DeleteDocumentRequest {
    return DeleteDocumentRequest.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<DeleteDocumentRequest>, I>>(object: I): DeleteDocumentRequest {
    const message = createBaseDeleteDocumentRequest();
    message.id = object.id ?? "";
    return message;
  },
};

function createBaseDeleteDocumentResponse(): DeleteDocumentResponse {
  return { deleted: false };
}

export const DeleteDocumentResponse: MessageFns<DeleteDocumentResponse> = {
  encode(message: DeleteDocumentResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
    if (message.deleted !== false) {
      writer.uint32(8).bool(message.deleted);
    }
    return writer;
  },

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

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

  fromJSON(object: any): DeleteDocumentResponse {
    return { deleted: isSet(object.deleted) ? globalThis.Boolean(object.deleted) : false };
  },

  toJSON(message: DeleteDocumentResponse): unknown {
    const obj: any = {};
    if (message.deleted !== false) {
      obj.deleted = message.deleted;
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<DeleteDocumentResponse>, I>>(base?: I): DeleteDocumentResponse {
    return DeleteDocumentResponse.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<DeleteDocumentResponse>, I>>(object: I): DeleteDocumentResponse {
    const message = createBaseDeleteDocumentResponse();
    message.deleted = object.deleted ?? false;
    return message;
  },
};

/**
 * Document ingestion. Every chunk must carry an explicit ACL: empty
 * ACL is default-deny and rejected with InvalidArgument (gRPC) /
 * 422 (HTTP).
 */
export type IngestionServiceService = typeof IngestionServiceService;
export const IngestionServiceService = {
  ingestDocument: {
    path: "/apf.ai.v1.IngestionService/IngestDocument" as const,
    requestStream: false as const,
    responseStream: false as const,
    requestSerialize: (value: IngestDocumentRequest): Buffer =>
      Buffer.from(IngestDocumentRequest.encode(value).finish()),
    requestDeserialize: (value: Buffer): IngestDocumentRequest => IngestDocumentRequest.decode(value),
    responseSerialize: (value: IngestDocumentResponse): Buffer =>
      Buffer.from(IngestDocumentResponse.encode(value).finish()),
    responseDeserialize: (value: Buffer): IngestDocumentResponse => IngestDocumentResponse.decode(value),
  },
  getDocument: {
    path: "/apf.ai.v1.IngestionService/GetDocument" as const,
    requestStream: false as const,
    responseStream: false as const,
    requestSerialize: (value: GetDocumentRequest): Buffer => Buffer.from(GetDocumentRequest.encode(value).finish()),
    requestDeserialize: (value: Buffer): GetDocumentRequest => GetDocumentRequest.decode(value),
    responseSerialize: (value: DocumentSummary): Buffer => Buffer.from(DocumentSummary.encode(value).finish()),
    responseDeserialize: (value: Buffer): DocumentSummary => DocumentSummary.decode(value),
  },
  deleteDocument: {
    path: "/apf.ai.v1.IngestionService/DeleteDocument" as const,
    requestStream: false as const,
    responseStream: false as const,
    requestSerialize: (value: DeleteDocumentRequest): Buffer =>
      Buffer.from(DeleteDocumentRequest.encode(value).finish()),
    requestDeserialize: (value: Buffer): DeleteDocumentRequest => DeleteDocumentRequest.decode(value),
    responseSerialize: (value: DeleteDocumentResponse): Buffer =>
      Buffer.from(DeleteDocumentResponse.encode(value).finish()),
    responseDeserialize: (value: Buffer): DeleteDocumentResponse => DeleteDocumentResponse.decode(value),
  },
} as const;

export interface IngestionServiceServer extends UntypedServiceImplementation {
  ingestDocument: handleUnaryCall<IngestDocumentRequest, IngestDocumentResponse>;
  getDocument: handleUnaryCall<GetDocumentRequest, DocumentSummary>;
  deleteDocument: handleUnaryCall<DeleteDocumentRequest, DeleteDocumentResponse>;
}

export interface IngestionServiceClient extends Client {
  ingestDocument(
    request: IngestDocumentRequest,
    callback: (error: ServiceError | null, response: IngestDocumentResponse) => void,
  ): ClientUnaryCall;
  ingestDocument(
    request: IngestDocumentRequest,
    metadata: Metadata,
    callback: (error: ServiceError | null, response: IngestDocumentResponse) => void,
  ): ClientUnaryCall;
  ingestDocument(
    request: IngestDocumentRequest,
    metadata: Metadata,
    options: Partial<CallOptions>,
    callback: (error: ServiceError | null, response: IngestDocumentResponse) => void,
  ): ClientUnaryCall;
  getDocument(
    request: GetDocumentRequest,
    callback: (error: ServiceError | null, response: DocumentSummary) => void,
  ): ClientUnaryCall;
  getDocument(
    request: GetDocumentRequest,
    metadata: Metadata,
    callback: (error: ServiceError | null, response: DocumentSummary) => void,
  ): ClientUnaryCall;
  getDocument(
    request: GetDocumentRequest,
    metadata: Metadata,
    options: Partial<CallOptions>,
    callback: (error: ServiceError | null, response: DocumentSummary) => void,
  ): ClientUnaryCall;
  deleteDocument(
    request: DeleteDocumentRequest,
    callback: (error: ServiceError | null, response: DeleteDocumentResponse) => void,
  ): ClientUnaryCall;
  deleteDocument(
    request: DeleteDocumentRequest,
    metadata: Metadata,
    callback: (error: ServiceError | null, response: DeleteDocumentResponse) => void,
  ): ClientUnaryCall;
  deleteDocument(
    request: DeleteDocumentRequest,
    metadata: Metadata,
    options: Partial<CallOptions>,
    callback: (error: ServiceError | null, response: DeleteDocumentResponse) => void,
  ): ClientUnaryCall;
}

export const IngestionServiceClient = makeGenericClientConstructor(
  IngestionServiceService,
  "apf.ai.v1.IngestionService",
) as unknown as {
  new (address: string, credentials: ChannelCredentials, options?: Partial<ClientOptions>): IngestionServiceClient;
  service: typeof IngestionServiceService;
  serviceName: string;
};

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

type DeepPartial<T> = T extends Builtin ? T
  : T extends Long ? string | number | Long : 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>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
type Exact<P, I extends P> = P extends Builtin ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function toTimestamp(date: Date): Timestamp {
  const seconds = numberToLong(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.toNumber() || 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 numberToLong(number: number) {
  return Long.fromNumber(number);
}

function isObject(value: any): boolean {
  return typeof value === "object" && value !== null;
}

function isSet(value: any): boolean {
  return value !== null && value !== undefined;
}

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<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
  fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
