// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../core/resource';
import { APIPromise } from '../core/api-promise';
import { type Uploadable } from '../core/uploads';
import { RequestOptions } from '../internal/request-options';
import { multipartFormRequestOptions } from '../internal/uploads';

export class ContentProvenanceChecks extends APIResource {
  /**
   * Check whether an image or audio file contains known OpenAI provenance signals.
   * [Learn more about content provenance](/api/docs/guides/content-provenance).
   *
   * If `not_detected`, it means the tool did not find supported signals in the
   * uploaded file. The content could still have been generated by OpenAI if the
   * metadata was stripped or has evidence of tampering, the watermark was degraded,
   * it comes from a legacy generation model, or it was created before provenance
   * signals were available. Content could also still be AI-generated by another
   * company's model, which the tool currently does not detect.
   */
  create(
    body: ContentProvenanceCheckCreateParams,
    options?: RequestOptions,
  ): APIPromise<ContentProvenanceCheck> {
    return this._client.post(
      '/content_provenance_checks',
      multipartFormRequestOptions({ body, ...options, __security: { bearerAuth: true } }, this._client),
    );
  }
}

export interface ContentProvenanceCheck {
  /**
   * The Unix timestamp, in seconds, when the provenance check was created.
   */
  created_at: number;

  /**
   * The object type. Always `content_provenance_check` for this endpoint.
   */
  object: 'content_provenance_check';

  /**
   * The provenance results that apply to the uploaded file. Image results include
   * C2PA and SynthID; audio results include SynthID.
   */
  results: Array<ContentProvenanceCheck.C2PA | ContentProvenanceCheck.SynthID>;
}

export namespace ContentProvenanceCheck {
  export interface C2PA {
    /**
     * The UTC RFC 3339 timestamp recorded by the provenance signal for when the asset
     * was generated, when available.
     */
    generated_at: string | null;

    /**
     * The C2PA manifest issuer, when available.
     */
    issuer: string | null;

    /**
     * The OpenAI model recorded by the provenance signal, when available.
     */
    model: string | null;

    /**
     * Whether a supported OpenAI C2PA provenance signal was detected. If
     * `not_detected`, it means the tool did not find supported signals in the uploaded
     * file. The content could still have been generated by OpenAI if the metadata was
     * stripped or has evidence of tampering, the watermark was degraded, it comes from
     * a legacy generation model, or it was created before provenance signals were
     * available. Content could also still be AI-generated by another company's model,
     * which the tool currently does not detect.
     */
    outcome: 'detected' | 'not_detected';

    /**
     * The provenance signal type. Always `c2pa`.
     */
    type: 'c2pa';

    /**
     * The validation status of the C2PA manifest in the uploaded image.
     */
    validation_state: 'trusted' | 'valid' | 'invalid' | 'not_present';
  }

  export interface SynthID {
    /**
     * The UTC RFC 3339 timestamp recorded by the provenance signal for when the asset
     * was generated, when available.
     */
    generated_at: string | null;

    /**
     * The OpenAI model recorded by the provenance signal, when available.
     */
    model: string | null;

    /**
     * Whether a supported OpenAI SynthID watermark was detected. If `not_detected`, it
     * means the tool did not find supported signals in the uploaded file. The content
     * could still have been generated by OpenAI if the metadata was stripped or has
     * evidence of tampering, the watermark was degraded, it comes from a legacy
     * generation model, or it was created before provenance signals were available.
     * Content could also still be AI-generated by another company's model, which the
     * tool currently does not detect.
     */
    outcome: 'detected' | 'not_detected';

    /**
     * The provenance signal type. Always `synthid`.
     */
    type: 'synthid';
  }
}

export interface ContentProvenanceCheckCreateParams {
  /**
   * The image or audio file to check for supported OpenAI provenance signals.
   */
  file: Uploadable;
}

export declare namespace ContentProvenanceChecks {
  export {
    type ContentProvenanceCheck as ContentProvenanceCheck,
    type ContentProvenanceCheckCreateParams as ContentProvenanceCheckCreateParams,
  };
}
