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

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export const MarketplaceFlagState = {
  Active: "active",
  Archived: "archived",
} as const;
export type MarketplaceFlagState = ClosedEnum<typeof MarketplaceFlagState>;

export const Category = {
  Experiment: "experiment",
  Flag: "flag",
} as const;
export type Category = ClosedEnum<typeof Category>;

export type MarketplaceFlag = {
  typeName: "marketplaceFlag";
  id: string;
  externalId: string;
  slug: string;
  origin: string;
  ownerId: string;
  projectId: string;
  resourceId: string;
  integrationConfigurationId: string;
  state: MarketplaceFlagState;
  name?: string | undefined;
  description?: string | undefined;
  category?: Category | undefined;
  createdAt?: number | undefined;
  updatedAt?: number | undefined;
};

/** @internal */
export const MarketplaceFlagState$inboundSchema: z.ZodNativeEnum<
  typeof MarketplaceFlagState
> = z.nativeEnum(MarketplaceFlagState);

/** @internal */
export const Category$inboundSchema: z.ZodNativeEnum<typeof Category> = z
  .nativeEnum(Category);

/** @internal */
export const MarketplaceFlag$inboundSchema: z.ZodType<
  MarketplaceFlag,
  z.ZodTypeDef,
  unknown
> = z.object({
  typeName: types.literal("marketplaceFlag"),
  id: types.string(),
  externalId: types.string(),
  slug: types.string(),
  origin: types.string(),
  ownerId: types.string(),
  projectId: types.string(),
  resourceId: types.string(),
  integrationConfigurationId: types.string(),
  state: MarketplaceFlagState$inboundSchema,
  name: types.optional(types.string()),
  description: types.optional(types.string()),
  category: types.optional(Category$inboundSchema),
  createdAt: types.optional(types.number()),
  updatedAt: types.optional(types.number()),
});

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