// 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 { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';

export class BaseEvents extends APIResource {
  static override readonly _key: readonly ['workflows', 'instances', 'events'] = Object.freeze([
    'workflows',
    'instances',
    'events',
  ] as const);

  /**
   * Sends an event to a running workflow instance to trigger state transitions.
   */
  create(
    eventType: string,
    params: EventCreateParams,
    options?: RequestOptions,
  ): APIPromise<EventCreateResponse> {
    const { account_id, workflow_name, instance_id, body } = params;
    return (
      this._client.post(
        path`/accounts/${account_id}/workflows/${workflow_name}/instances/${instance_id}/events/${eventType}`,
        { body: body, ...options },
      ) as APIPromise<{ result: EventCreateResponse }>
    )._thenUnwrap((obj) => obj.result);
  }
}
export class Events extends BaseEvents {}

export interface EventCreateResponse {
  instanceId: string;

  /**
   * Accepts ISO 8601 with no timezone offsets and in UTC.
   */
  timestamp: string;
}

export interface EventCreateParams {
  /**
   * Path param
   */
  account_id: string;

  /**
   * Path param
   */
  workflow_name: string;

  /**
   * Path param: Instance identifier. User-created instances match
   * `^[a-zA-Z0-9_][a-zA-Z0-9-_]*$` (max 100 characters); cron-triggered instances
   * can use a longer, system-generated id derived from the cron expression.
   */
  instance_id: string;

  /**
   * Body param
   */
  body: unknown;
}

export declare namespace Events {
  export { type EventCreateResponse as EventCreateResponse, type EventCreateParams as EventCreateParams };
}
