import { array, number, object, string, boolean } from "yup";
export const schema = object({
    lat: number()
        .min(-90, "Must be a valid latitude.")
        .max(90, "Must be a valid latitude.")
        .when("geographyId", {
        is: (geographyId) => typeof geographyId === "string",
        then: (fieldSchema) => fieldSchema.optional(),
        otherwise: (fieldSchema) => fieldSchema.required(),
    }),
    lng: number()
        .min(-180, "Must be a valid longitude.")
        .max(180, "Must be a valid longitude.")
        .when("geographyId", {
        is: (geographyId) => typeof geographyId === "string",
        then: (fieldSchema) => fieldSchema.optional(),
        otherwise: (fieldSchema) => fieldSchema.required(),
    }),
    addressLabel: string().when("geographyId", {
        is: (geographyId) => typeof geographyId === "string",
        then: (fieldSchema) => fieldSchema.optional(),
        otherwise: (fieldSchema) => fieldSchema.required(),
    }),
    geographyId: string().optional(),
    consentText: string().optional(),
    consentLinks: array().of(object({
        text: string().required("Link text is required."),
        href: string()
            .url("Link href must be a valid URL.")
            .required("Link href is required."),
    })),
    hideAttribution: boolean().optional(),
    customData: object()
        .test("valid-data", "Keys must contain only lowercase letters and underscores (max 100 chars). Values must be strings, numbers, null or booleans (max 2048 chars). Maximum 50 key/value pairs allowed", (value) => {
        if (!value)
            return true;
        // Check that there are no more than 50 key/value pairs
        if (Object.keys(value).length > 50)
            return false;
        // Check that all keys are strings, are non-empty, and are within 2048 chars
        const validKeys = Object.keys(value).every((key) => typeof key === "string" && key.trim() !== "" && key.length <= 100);
        // Check that all values are strings, numbers, null or booleans, and within 2048 chars
        const validValues = Object.values(value).every((val) => {
            if (typeof val === "string") {
                return val.length <= 2048;
            }
            if (typeof val === "number") {
                return val.toString().length <= 2048;
            }
            if (typeof val === "boolean") {
                return true;
            }
            if (val === null) {
                return true;
            }
            return false;
        });
        return validKeys && validValues;
    })
        .optional(),
}).noUnknown(true);
//# sourceMappingURL=schema.js.map