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

/* eslint-disable */
import { DSSELogEntryV002, DSSERequestV002 } from "./dsse";
import { HashedRekordLogEntryV002, HashedRekordRequestV002 } from "./hashedrekord";

/**
 * Entry is the message that is canonicalized and uploaded to the log.
 * This format is meant to be compliant with Rekor v1 entries in that
 * the `apiVersion` and `kind` can be parsed before parsing the spec.
 * Clients are expected to understand and handle the differences in the
 * contents of `spec` between Rekor v1 (a polymorphic OpenAPI defintion)
 * and Rekor v2 (a typed proto defintion).
 */
export interface Entry {
  kind: string;
  apiVersion: string;
  spec: Spec | undefined;
}

/** Spec contains one of the Rekor entry types. */
export interface Spec {
  spec: { $case: "hashedRekordV002"; hashedRekordV002: HashedRekordLogEntryV002 } | {
    $case: "dsseV002";
    dsseV002: DSSELogEntryV002;
  } | undefined;
}

/** Create a new HashedRekord or DSSE */
export interface CreateEntryRequest {
  spec: { $case: "hashedRekordRequestV002"; hashedRekordRequestV002: HashedRekordRequestV002 } | {
    $case: "dsseRequestV002";
    dsseRequestV002: DSSERequestV002;
  } | undefined;
}

export const Entry: MessageFns<Entry> = {
  fromJSON(object: any): Entry {
    return {
      kind: isSet(object.kind) ? globalThis.String(object.kind) : "",
      apiVersion: isSet(object.apiVersion) ? globalThis.String(object.apiVersion) : "",
      spec: isSet(object.spec) ? Spec.fromJSON(object.spec) : undefined,
    };
  },

  toJSON(message: Entry): unknown {
    const obj: any = {};
    if (message.kind !== "") {
      obj.kind = message.kind;
    }
    if (message.apiVersion !== "") {
      obj.apiVersion = message.apiVersion;
    }
    if (message.spec !== undefined) {
      obj.spec = Spec.toJSON(message.spec);
    }
    return obj;
  },
};

export const Spec: MessageFns<Spec> = {
  fromJSON(object: any): Spec {
    return {
      spec: isSet(object.hashedRekordV002)
        ? { $case: "hashedRekordV002", hashedRekordV002: HashedRekordLogEntryV002.fromJSON(object.hashedRekordV002) }
        : isSet(object.dsseV002)
        ? { $case: "dsseV002", dsseV002: DSSELogEntryV002.fromJSON(object.dsseV002) }
        : undefined,
    };
  },

  toJSON(message: Spec): unknown {
    const obj: any = {};
    if (message.spec?.$case === "hashedRekordV002") {
      obj.hashedRekordV002 = HashedRekordLogEntryV002.toJSON(message.spec.hashedRekordV002);
    } else if (message.spec?.$case === "dsseV002") {
      obj.dsseV002 = DSSELogEntryV002.toJSON(message.spec.dsseV002);
    }
    return obj;
  },
};

export const CreateEntryRequest: MessageFns<CreateEntryRequest> = {
  fromJSON(object: any): CreateEntryRequest {
    return {
      spec: isSet(object.hashedRekordRequestV002)
        ? {
          $case: "hashedRekordRequestV002",
          hashedRekordRequestV002: HashedRekordRequestV002.fromJSON(object.hashedRekordRequestV002),
        }
        : isSet(object.dsseRequestV002)
        ? { $case: "dsseRequestV002", dsseRequestV002: DSSERequestV002.fromJSON(object.dsseRequestV002) }
        : undefined,
    };
  },

  toJSON(message: CreateEntryRequest): unknown {
    const obj: any = {};
    if (message.spec?.$case === "hashedRekordRequestV002") {
      obj.hashedRekordRequestV002 = HashedRekordRequestV002.toJSON(message.spec.hashedRekordRequestV002);
    } else if (message.spec?.$case === "dsseRequestV002") {
      obj.dsseRequestV002 = DSSERequestV002.toJSON(message.spec.dsseRequestV002);
    }
    return obj;
  },
};

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

interface MessageFns<T> {
  fromJSON(object: any): T;
  toJSON(message: T): unknown;
}
