import { GraphQLError, GraphQLScalarType, Kind, } from "graphql";
import { z } from "zod";
export const type = "string";
export const typedef = "scalar Currency";
export const schema = z.string();
export const stringSchema = "z.string()";
const currencyValidation = (value) => {
    if (typeof value !== "string") {
        throw new GraphQLError(`Value is not string: ${JSON.stringify(value)}`);
    }
    const result = schema.safeParse(value);
    if (result.success)
        return result.data;
    throw new GraphQLError(result.error.message);
};
export const config = {
    name: "Currency",
    description: "A custom scalar that represents a Currency Code string",
    serialize: currencyValidation,
    parseValue: currencyValidation,
    parseLiteral: (value) => {
        if (value.kind !== Kind.STRING) {
            throw new GraphQLError(`Value is not a valid string: ${value.kind}`, {
                nodes: value,
            });
        }
        return currencyValidation(value.value);
    },
};
export const scalar = new GraphQLScalarType(config);
//# sourceMappingURL=Currency.js.map