// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.7.5
//   protoc               v6.30.2
// source: rekor/v2/dsse.proto

/* eslint-disable */
import { Envelope } from "../../envelope";
import { HashOutput } from "../../sigstore_common";
import { Signature, Verifier } from "./verifier";

/** A request to add a DSSE v0.0.2 entry to the log */
export interface DSSERequestV002 {
  /** A DSSE envelope */
  envelope:
    | Envelope
    | undefined;
  /** All necessary verification material to verify all signatures embedded in the envelope */
  verifiers: Verifier[];
}

export interface DSSELogEntryV002 {
  /** The hash of the DSSE payload */
  payloadHash:
    | HashOutput
    | undefined;
  /** Signatures and their associated verification material used to verify the payload */
  signatures: Signature[];
}

export const DSSERequestV002: MessageFns<DSSERequestV002> = {
  fromJSON(object: any): DSSERequestV002 {
    return {
      envelope: isSet(object.envelope) ? Envelope.fromJSON(object.envelope) : undefined,
      verifiers: globalThis.Array.isArray(object?.verifiers)
        ? object.verifiers.map((e: any) => Verifier.fromJSON(e))
        : [],
    };
  },

  toJSON(message: DSSERequestV002): unknown {
    const obj: any = {};
    if (message.envelope !== undefined) {
      obj.envelope = Envelope.toJSON(message.envelope);
    }
    if (message.verifiers?.length) {
      obj.verifiers = message.verifiers.map((e) => Verifier.toJSON(e));
    }
    return obj;
  },
};

export const DSSELogEntryV002: MessageFns<DSSELogEntryV002> = {
  fromJSON(object: any): DSSELogEntryV002 {
    return {
      payloadHash: isSet(object.payloadHash) ? HashOutput.fromJSON(object.payloadHash) : undefined,
      signatures: globalThis.Array.isArray(object?.signatures)
        ? object.signatures.map((e: any) => Signature.fromJSON(e))
        : [],
    };
  },

  toJSON(message: DSSELogEntryV002): unknown {
    const obj: any = {};
    if (message.payloadHash !== undefined) {
      obj.payloadHash = HashOutput.toJSON(message.payloadHash);
    }
    if (message.signatures?.length) {
      obj.signatures = message.signatures.map((e) => Signature.toJSON(e));
    }
    return obj;
  },
};

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

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