/**
 * Generated by orval v8.5.3 🍺
 * Do not edit manually.
 * Api
 * API specification
 * OpenAPI spec version: 0.1.0
 */
import * as zod from "zod";

/**
 * Returns server health status
 * @summary Health check
 */
export const HealthCheckResponse = zod.object({
  status: zod.string(),
});

/**
 * Accepts a request, creates a job row, and issues an eval fee Lightning invoice.
 * @summary Create a new agent job
 */

export const CreateJobBody = zod.object({
  request: zod.string().min(1),
});

/**
 * Returns current job state. Automatically advances the state machine when a pending invoice is found to be paid.
 * @summary Get job status
 */
export const GetJobParams = zod.object({
  id: zod.coerce.string(),
});

export const GetJobResponse = zod.object({
  jobId: zod.string(),
  state: zod.enum([
    "awaiting_eval_payment",
    "evaluating",
    "rejected",
    "awaiting_work_payment",
    "executing",
    "complete",
    "failed",
  ]),
  createdAt: zod
    .date()
    .describe("ISO 8601 timestamp of job creation (always present)"),
  completedAt: zod
    .date()
    .nullish()
    .describe(
      "ISO 8601 timestamp of job completion; null when not yet complete",
    ),
  evalInvoice: zod
    .object({
      paymentRequest: zod.string(),
      amountSats: zod.number(),
    })
    .optional(),
  workInvoice: zod
    .object({
      paymentRequest: zod.string(),
      amountSats: zod.number(),
    })
    .optional(),
  pricingBreakdown: zod
    .object({
      estimatedCostUsd: zod
        .number()
        .optional()
        .describe(
          "Total estimated cost in USD (token cost + DO infra + margin)",
        ),
      marginPct: zod
        .number()
        .optional()
        .describe("Originator margin percentage applied"),
      btcPriceUsd: zod
        .number()
        .optional()
        .describe("BTC\/USD spot price used to convert the invoice to sats"),
    })
    .optional()
    .describe(
      "Cost breakdown shown with the work invoice (estimations at invoice-creation time)",
    ),
  reason: zod.string().optional(),
  result: zod.string().optional(),
  costLedger: zod
    .object({
      actualInputTokens: zod.number().optional(),
      actualOutputTokens: zod.number().optional(),
      totalTokens: zod
        .number()
        .optional()
        .describe("Sum of actualInputTokens + actualOutputTokens"),
      actualCostUsd: zod
        .number()
        .optional()
        .describe("Raw Anthropic token cost (no infra, no margin)"),
      actualChargeUsd: zod
        .number()
        .optional()
        .describe(
          "What we honestly charged in USD (actual token cost + DO infra + margin)",
        ),
      estimatedCostUsd: zod
        .number()
        .optional()
        .describe("Original estimate used to create the work invoice"),
      actualAmountSats: zod
        .number()
        .optional()
        .describe(
          "Honest sats charge (actual cost converted at the locked BTC price)",
        ),
      workAmountSats: zod
        .number()
        .optional()
        .describe("Amount the user originally paid in sats"),
      refundAmountSats: zod
        .number()
        .optional()
        .describe(
          "Sats owed back to the user (workAmountSats - actualAmountSats, >= 0)",
        ),
      refundState: zod
        .enum(["not_applicable", "pending", "paid"])
        .optional()
        .describe("Lifecycle of the refund for this job"),
      marginPct: zod.number().optional(),
      btcPriceUsd: zod
        .number()
        .optional()
        .describe("BTC\/USD price locked at invoice creation time"),
    })
    .optional()
    .describe("Honest post-work accounting stored after the job completes"),
  errorMessage: zod.string().optional(),
});

/**
 * After a job completes, if the actual cost (tokens used + infra + margin) was
less than the work invoice amount, the difference is owed back to the user.
Submit a BOLT11 invoice for exactly `refundAmountSats` to receive the payment.
Idempotent: returns 409 if already paid or if no refund is owed.

 * @summary Claim a refund for overpayment
 */
export const ClaimRefundParams = zod.object({
  id: zod.coerce.string(),
});

export const ClaimRefundBody = zod.object({
  invoice: zod.string().describe("BOLT11 invoice for exactly refundAmountSats"),
});

export const ClaimRefundResponse = zod.object({
  ok: zod.boolean(),
  refundAmountSats: zod.number(),
  paymentHash: zod.string(),
  message: zod.string(),
});

/**
 * Opens a new session. Pay the returned Lightning invoice to activate it.
Once active, use the `macaroon` from GET /sessions/:id to authenticate requests.
Deposits: 100–10,000 sats. Sessions expire after 24 h of inactivity.

 * @summary Create a pre-funded session
 */
export const createSessionBodyAmountSatsMin = 100;
export const createSessionBodyAmountSatsMax = 10000;

export const CreateSessionBody = zod.object({
  amount_sats: zod
    .number()
    .min(createSessionBodyAmountSatsMin)
    .max(createSessionBodyAmountSatsMax)
    .describe("Deposit amount (100–10,000 sats)"),
});

/**
 * Returns current state, balance, and pending invoice info. Auto-advances on payment.
 * @summary Get session status
 */
export const GetSessionParams = zod.object({
  id: zod.coerce.string(),
});

export const GetSessionResponse = zod.object({
  sessionId: zod.string(),
  state: zod.enum(["awaiting_payment", "active", "paused", "expired"]),
  balanceSats: zod.number(),
  minimumBalanceSats: zod.number().optional(),
  macaroon: zod
    .string()
    .optional()
    .describe(
      "Bearer token for authenticating requests; present when active or paused",
    ),
  expiresAt: zod.date().optional(),
  invoice: zod
    .object({
      paymentRequest: zod.string().optional(),
      amountSats: zod.number().optional(),
      paymentHash: zod
        .string()
        .optional()
        .describe("Only present in stub\/dev mode"),
    })
    .optional()
    .describe("Present when state is awaiting_payment"),
  pendingTopup: zod
    .object({
      paymentRequest: zod.string().optional(),
      amountSats: zod.number().optional(),
      paymentHash: zod
        .string()
        .optional()
        .describe("Only present in stub\/dev mode"),
    })
    .optional()
    .describe("Present when a topup invoice is outstanding"),
});

/**
 * Runs eval + work and debits the actual compute cost from the session balance.
Rejected requests still incur a small eval fee. Requires `Authorization: Bearer <macaroon>`.

 * @summary Submit a request against a session balance
 */
export const SubmitSessionRequestParams = zod.object({
  id: zod.coerce.string(),
});

export const SubmitSessionRequestBody = zod.object({
  request: zod.string().min(1),
});

export const SubmitSessionRequestResponse = zod.object({
  requestId: zod.string(),
  state: zod.enum(["complete", "rejected", "failed"]),
  result: zod.string().optional(),
  reason: zod.string().optional(),
  errorMessage: zod.string().optional(),
  debitedSats: zod.number(),
  balanceRemaining: zod.number(),
  cost: zod
    .object({
      evalSats: zod.number().optional(),
      workSats: zod.number().optional(),
      totalSats: zod.number().optional(),
      btcPriceUsd: zod.number().optional(),
    })
    .optional(),
});

/**
 * Creates a new Lightning invoice to top up the session balance.
Only one pending topup at a time. Paying it resumes a paused session.

 * @summary Add sats to a session
 */
export const TopupSessionParams = zod.object({
  id: zod.coerce.string(),
});

export const topupSessionBodyAmountSatsMin = 100;
export const topupSessionBodyAmountSatsMax = 10000;

export const TopupSessionBody = zod.object({
  amount_sats: zod
    .number()
    .min(topupSessionBodyAmountSatsMin)
    .max(topupSessionBodyAmountSatsMax)
    .describe("Deposit amount (100–10,000 sats)"),
});

export const TopupSessionResponse = zod.object({
  sessionId: zod.string(),
  topup: zod.object({
    paymentRequest: zod.string().optional(),
    amountSats: zod.number().optional(),
    paymentHash: zod
      .string()
      .optional()
      .describe("Only present in stub\/dev mode"),
  }),
});

/**
 * Runs the agent without payment. Limited to 5 requests per IP per hour.
 * @summary Free demo (rate-limited)
 */
export const RunDemoQueryParams = zod.object({
  request: zod.coerce.string(),
});

export const RunDemoResponse = zod.object({
  result: zod.string(),
});

/**
 * @summary List all conversations
 */
export const ListGeminiConversationsResponseItem = zod.object({
  id: zod.number(),
  title: zod.string(),
  createdAt: zod.date(),
});
export const ListGeminiConversationsResponse = zod.array(
  ListGeminiConversationsResponseItem,
);

/**
 * @summary Create a new conversation
 */
export const CreateGeminiConversationBody = zod.object({
  title: zod.string(),
});

/**
 * @summary Get conversation with messages
 */
export const GetGeminiConversationParams = zod.object({
  id: zod.coerce.number(),
});

export const GetGeminiConversationResponse = zod.object({
  id: zod.number(),
  title: zod.string(),
  createdAt: zod.date(),
  messages: zod.array(
    zod.object({
      id: zod.number(),
      conversationId: zod.number(),
      role: zod.string(),
      content: zod.string(),
      createdAt: zod.date(),
    }),
  ),
});

/**
 * @summary Delete a conversation
 */
export const DeleteGeminiConversationParams = zod.object({
  id: zod.coerce.number(),
});

/**
 * @summary List messages in a conversation
 */
export const ListGeminiMessagesParams = zod.object({
  id: zod.coerce.number(),
});

export const ListGeminiMessagesResponseItem = zod.object({
  id: zod.number(),
  conversationId: zod.number(),
  role: zod.string(),
  content: zod.string(),
  createdAt: zod.date(),
});
export const ListGeminiMessagesResponse = zod.array(
  ListGeminiMessagesResponseItem,
);

/**
 * @summary Send a message and receive an AI response (SSE stream)
 */
export const SendGeminiMessageParams = zod.object({
  id: zod.coerce.number(),
});

export const SendGeminiMessageBody = zod.object({
  content: zod.string(),
  model: zod
    .string()
    .optional()
    .describe("Gemini model override (default: gemini-3-flash-preview)"),
});

/**
 * @summary Generate an image from a text prompt
 */
export const GenerateGeminiImageBody = zod.object({
  prompt: zod.string(),
});

export const GenerateGeminiImageResponse = zod.object({
  b64_json: zod.string(),
  mimeType: zod.string(),
});
