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

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 BaseFieldDefinitionType = {
  Enum: "ENUM",
  Text: "TEXT",
  Int: "INT",
  Float: "FLOAT",
  Bool: "BOOL",
  Timestamp: "TIMESTAMP",
  Array: "ARRAY",
  Map: "MAP",
} as const;
export type BaseFieldDefinitionType = OpenEnum<typeof BaseFieldDefinitionType>;

export const SupportedOperator = {
  Lt: "lt",
  Lte: "lte",
  Gt: "gt",
  Gte: "gte",
  Startswith: "startswith",
  Istartswith: "istartswith",
  Endswith: "endswith",
  Iendswith: "iendswith",
  Contains: "contains",
  Icontains: "icontains",
  Matches: "matches",
  Notcontains: "notcontains",
  Inotcontains: "inotcontains",
  Eq: "eq",
  Neq: "neq",
  Isnull: "isnull",
  Includes: "includes",
  Excludes: "excludes",
  LenEq: "len_eq",
} as const;
export type SupportedOperator = OpenEnum<typeof SupportedOperator>;

export type BaseFieldDefinition = {
  name: string;
  label: string;
  type: BaseFieldDefinitionType;
  group?: string | null | undefined;
  supportedOperators: Array<SupportedOperator>;
};

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

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

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

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