"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = exports.EMAIL_REGEX = exports.Coordinate = void 0;
exports.getFirstTypeAnnotation = getFirstTypeAnnotation;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-server-foundation/type-metadata-runtime"));
const reflection_1 = require("../reflection");
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":7}]]", []);
let _CoordinateMetadata_1;
class Coordinate {
    x;
    y;
    static __tsfType = _CoordinateMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"Coordinate\",\"typeName\":\"Coordinate\",\"classType\":{\"$tsf\":0},\"properties\":[{\"name\":\"x\",\"type\":{\"$tsfType\":0},\"optional\":false},{\"name\":\"y\",\"type\":{\"$tsfType\":0},\"optional\":false}],\"methods\":[],\"hasConstructor\":false,\"constructorParameters\":[]}]", [() => Coordinate], __tsf_metadata_type);
}
exports.Coordinate = Coordinate;
_CoordinateMetadata_1.classType = Coordinate;
Coordinate.__tsfType = _CoordinateMetadata_1;
function validateDate(value) {
    if (!(value instanceof Date) || Number.isNaN(value.getTime())) {
        return new reflection_1.ValidatorError('invalidDate', 'The date is invalid.');
    }
}
reflection_1.validationRegistry.register('validDate', validateDate);
function getFirstTypeAnnotation(t, ...names) {
    for (const name of names) {
        const annotation = reflection_1.typeAnnotation.getType(t, name);
        if (annotation)
            return annotation;
    }
}
reflection_1.deserializer.addDecorator(t => getFirstTypeAnnotation(t, 'tsf:trim') !== undefined, (_type, state) => {
    state.addTransform(value => (typeof value === 'string' ? value.trim() : value));
});
exports.EMAIL_REGEX = /^[a-z0-9_+.-]+@[a-z0-9-.]+\.[a-z]+$/i;
exports.__tsfTypeAliases = _a.decodeCompactMetadataV1("[1,{\"DateString\":{\"kind\":13,\"types\":[{\"kind\":6},{\"kind\":2,\"typeName\":\"Format\",\"validation\":[{\"name\":\"pattern\",\"args\":[{\"kind\":10,\"literal\":\"^\\\\d{4}-\\\\d{2}-\\\\d{2}$\"}]}]},{\"kind\":2,\"typeName\":\"DatabaseField\",\"database\":{\"*\":{\"type\":\"DATE\"}}},{\"kind\":2,\"typeName\":\"TypeAnnotation\",\"annotations\":{\"tsf:type\":{\"kind\":10,\"literal\":\"date\"}}}],\"typeName\":\"DateString\"},\"EmailAddress\":{\"kind\":13,\"types\":[{\"kind\":6},{\"kind\":2,\"typeName\":\"Format\",\"validation\":[{\"name\":\"pattern\",\"args\":[{\"kind\":10,\"literal\":\"^[a-zA-Z0-9_+.-]+@[a-zA-Z0-9-.]+\\\\.[a-zA-Z]+$\"}]}]}],\"typeName\":\"EmailAddress\"},\"HasDefault\":{\"kind\":2,\"typeName\":\"TypeAnnotation\",\"annotations\":{\"tsf:hasDefault\":{\"kind\":4}},\"typeName\":\"HasDefault\"},\"MySQLCoordinate\":{\"kind\":13,\"types\":[{\"kind\":16,\"typeName\":\"Coordinate\",\"classType\":{\"$tsf\":0}},{\"kind\":2,\"typeName\":\"MySQL\",\"database\":{\"mysql\":{\"type\":\"point\"}}}],\"typeName\":\"MySQLCoordinate\"},\"NonEmptyTrimmedString\":{\"kind\":13,\"types\":[{\"kind\":6},{\"kind\":2,\"typeName\":\"TypeAnnotation\",\"annotations\":{\"tsf:trim\":{\"kind\":4}}},{\"kind\":2,\"typeName\":\"MinLength\",\"validation\":[{\"name\":\"minLength\",\"args\":[{\"kind\":10,\"literal\":1}]}]}],\"typeName\":\"NonEmptyTrimmedString\"},\"NullableMySQLCoordinate\":{\"kind\":12,\"types\":[{\"kind\":13,\"types\":[{\"kind\":16,\"typeName\":\"Coordinate\",\"classType\":{\"$tsf\":0}},{\"kind\":2,\"typeName\":\"MySQL\",\"database\":{\"mysql\":{\"type\":\"point\"}}}]},{\"kind\":5}],\"typeName\":\"NullableMySQLCoordinate\"},\"TrimmedString\":{\"kind\":13,\"types\":[{\"kind\":6},{\"kind\":2,\"typeName\":\"TypeAnnotation\",\"annotations\":{\"tsf:trim\":{\"kind\":4}}}],\"typeName\":\"TrimmedString\"},\"UUID\":{\"kind\":13,\"types\":[{\"kind\":6},{\"kind\":2,\"typeName\":\"Format\",\"validation\":[{\"name\":\"pattern\",\"args\":[{\"kind\":10,\"literal\":\"^(?:urn:uuid:)?[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$\"}]}]},{\"kind\":2,\"typeName\":\"TypeAnnotation\",\"annotations\":{\"tsf:type\":{\"kind\":10,\"literal\":\"uuid\"}}}],\"typeName\":\"UUID\"},\"UnsignedNumber\":{\"kind\":13,\"types\":[{\"kind\":7},{\"kind\":2,\"typeName\":\"Minimum\",\"validation\":[{\"name\":\"minimum\",\"args\":[{\"kind\":10,\"literal\":0}]}]}],\"typeName\":\"UnsignedNumber\"},\"UuidString\":{\"kind\":13,\"types\":[{\"kind\":6},{\"kind\":2,\"typeName\":\"Format\",\"validation\":[{\"name\":\"pattern\",\"args\":[{\"kind\":10,\"literal\":\"^(?:urn:uuid:)?[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$\"}]}]},{\"kind\":2,\"typeName\":\"TypeAnnotation\",\"annotations\":{\"tsf:type\":{\"kind\":10,\"literal\":\"uuidString\"}}}],\"typeName\":\"UuidString\"},\"ValidDate\":{\"kind\":13,\"types\":[{\"kind\":16,\"typeName\":\"Date\",\"classType\":{\"$tsf\":1}},{\"kind\":2,\"typeName\":\"Validator\",\"validation\":[{\"name\":\"validator\",\"args\":[{\"kind\":10,\"literal\":\"validDate\"}]}]}],\"typeName\":\"ValidDate\"}}]", [() => (typeof Coordinate !== "undefined" ? Coordinate : (typeof exports !== "undefined" ? exports.Coordinate : undefined)), () => (typeof Date !== "undefined" ? Date : (typeof exports !== "undefined" ? exports.Date : undefined))], __tsf_metadata_type);
//# sourceMappingURL=type-annotations.js.map