import { FieldPresence, FieldSchema, StructureSchema, ValueType } from '@ephox/boulder';
import { Adt, Fun, Id, Optional } from '@ephox/katamari';
const adt = Adt.generate([
    { required: ['data'] },
    { external: ['data'] },
    { optional: ['data'] },
    { group: ['data'] }
]);
const fFactory = FieldSchema.defaulted('factory', { sketch: Fun.identity });
const fSchema = FieldSchema.defaulted('schema', []);
const fName = FieldSchema.required('name');
const fPname = FieldSchema.field('pname', 'pname', FieldPresence.defaultedThunk((typeSpec) => '<alloy.' + Id.generate(typeSpec.name) + '>'), ValueType.anyValue());
// Groups cannot choose their schema.
const fGroupSchema = FieldSchema.customField('schema', () => [
    FieldSchema.option('preprocess')
]);
const fDefaults = FieldSchema.defaulted('defaults', Fun.constant({}));
const fOverrides = FieldSchema.defaulted('overrides', Fun.constant({}));
const requiredSpec = StructureSchema.objOf([
    fFactory, fSchema, fName, fPname, fDefaults, fOverrides
]);
const externalSpec = StructureSchema.objOf([
    fFactory, fSchema, fName, fDefaults, fOverrides
]);
const optionalSpec = StructureSchema.objOf([
    fFactory, fSchema, fName, fPname, fDefaults, fOverrides
]);
const groupSpec = StructureSchema.objOf([
    fFactory, fGroupSchema, fName,
    FieldSchema.required('unit'),
    fPname, fDefaults, fOverrides
]);
const asNamedPart = (part) => {
    return part.fold(Optional.some, Optional.none, Optional.some, Optional.some);
};
const name = (part) => {
    const get = (data) => data.name;
    return part.fold(get, get, get, get);
};
const asCommon = (part) => {
    return part.fold(Fun.identity, Fun.identity, Fun.identity, Fun.identity);
};
const convert = (adtConstructor, partSchema) => (spec) => {
    const data = StructureSchema.asRawOrDie('Converting part type', partSchema, spec);
    return adtConstructor(data);
};
const required = convert(adt.required, requiredSpec);
const external = convert(adt.external, externalSpec);
const optional = convert(adt.optional, optionalSpec);
const group = convert(adt.group, groupSpec);
const original = Fun.constant('entirety');
export { required, external, optional, group, asNamedPart, name, asCommon, original };
//# sourceMappingURL=PartType.js.map