/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 32bf85982e0b
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const OtelFieldDefinitionType = {
  Enum: "ENUM",
  Text: "TEXT",
  Int: "INT",
  Float: "FLOAT",
  Bool: "BOOL",
  Timestamp: "TIMESTAMP",
  Array: "ARRAY",
  Map: "MAP",
} as const;
export type OtelFieldDefinitionType = OpenEnum<typeof OtelFieldDefinitionType>;

export const OtelFieldDefinitionSupportedOperator = {
  Eq: "eq",
  Neq: "neq",
  Lt: "lt",
  Lte: "lte",
  Gt: "gt",
  Gte: "gte",
  Like: "like",
  Ilike: "ilike",
  NotLike: "not_like",
  NotIlike: "not_ilike",
  Between: "between",
  NotBetween: "not_between",
  In: "in",
  NotIn: "not_in",
  Exists: "exists",
  NotExists: "not_exists",
  Regexp: "regexp",
  NotRegexp: "not_regexp",
  Contains: "contains",
  NotContains: "not_contains",
  Has: "has",
  HasAny: "hasAny",
  HasAll: "hasAll",
  HasToken: "hasToken",
} as const;
export type OtelFieldDefinitionSupportedOperator = OpenEnum<
  typeof OtelFieldDefinitionSupportedOperator
>;

export type OtelFieldDefinition = {
  name: string;
  label: string;
  type: OtelFieldDefinitionType;
  group?: string | null | undefined;
  supportedOperators: Array<OtelFieldDefinitionSupportedOperator>;
};

/** @internal */
export const OtelFieldDefinitionType$inboundSchema: z.ZodType<
  OtelFieldDefinitionType,
  unknown
> = openEnums.inboundSchema(OtelFieldDefinitionType);

/** @internal */
export const OtelFieldDefinitionSupportedOperator$inboundSchema: z.ZodType<
  OtelFieldDefinitionSupportedOperator,
  unknown
> = openEnums.inboundSchema(OtelFieldDefinitionSupportedOperator);

/** @internal */
export const OtelFieldDefinition$inboundSchema: z.ZodType<
  OtelFieldDefinition,
  unknown
> = z.object({
  name: z.string(),
  label: z.string(),
  type: OtelFieldDefinitionType$inboundSchema,
  group: z.nullable(z.string()).optional(),
  supported_operators: z.array(
    OtelFieldDefinitionSupportedOperator$inboundSchema,
  ),
}).transform((v) => {
  return remap$(v, {
    "supported_operators": "supportedOperators",
  });
});

export function otelFieldDefinitionFromJSON(
  jsonString: string,
): SafeParseResult<OtelFieldDefinition, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => OtelFieldDefinition$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'OtelFieldDefinition' from JSON`,
  );
}
