import { Type, type Static } from "@sinclair/typebox";

export const ProviderOptionsSchema = Type.Object({
  defaultSearchLimit: Type.Optional(Type.Integer({ minimum: 1 })),
  defaultFetchTextMaxCharacters: Type.Optional(Type.Integer({ minimum: 1 })),
  defaultFetchHighlightsMaxCharacters: Type.Optional(Type.Integer({ minimum: 1 })),
});

export const ExaProviderConfigSchema = Type.Object({
  name: Type.String({ minLength: 1 }),
  type: Type.Literal("exa"),
  apiKey: Type.String({ minLength: 1 }),
  options: Type.Optional(ProviderOptionsSchema),
});

export const WebSearchConfigSchema = Type.Object({
  defaultProvider: Type.String({ minLength: 1 }),
  providers: Type.Array(ExaProviderConfigSchema, { minItems: 1 }),
});

export const WebSearchParamsSchema = Type.Object({
  query: Type.String({ minLength: 1, description: "Search query" }),
  limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 25 })),
  includeDomains: Type.Optional(Type.Array(Type.String())),
  excludeDomains: Type.Optional(Type.Array(Type.String())),
  startPublishedDate: Type.Optional(Type.String()),
  endPublishedDate: Type.Optional(Type.String()),
  category: Type.Optional(Type.String()),
  provider: Type.Optional(Type.String()),
});

export const WebFetchParamsSchema = Type.Object({
  urls: Type.Array(Type.String(), { minItems: 1 }),
  text: Type.Optional(Type.Boolean()),
  highlights: Type.Optional(Type.Boolean()),
  summary: Type.Optional(Type.Boolean()),
  textMaxCharacters: Type.Optional(Type.Integer({ minimum: 1 })),
  provider: Type.Optional(Type.String()),
});

export type ProviderOptions = Static<typeof ProviderOptionsSchema>;
export type ExaProviderConfig = Static<typeof ExaProviderConfigSchema>;
export type WebSearchConfig = Static<typeof WebSearchConfigSchema>;
export type WebSearchParams = Static<typeof WebSearchParamsSchema>;
export type WebFetchParams = Static<typeof WebFetchParamsSchema>;
