/**
 * Angular ReactiveForms validator generation from Property metadata.
 * Each helper returns stringified validator expressions ready to emit verbatim.
 */
/**
 * Build the list of Angular `Validators.*` expressions for the generated form control.
 *
 * Primary-key ids (`type === 'id'` with no `widget`) are opaque and never editable — they
 * skip validators entirely. In `new` mode `useGraphqlCreate` auto-generates the UUID; in
 * `edit` mode the id comes intact from the resolver. Validators here would only fight
 * the framework.
 *
 * Foreign-key ids (`type === 'id'` WITH a `widget`, e.g. `select` / `grid-select-element`
 * since SPEC-09) ARE user-editable, so they get the normal validators.
 */
export function getValidators(property) {
    if (property.type === 'id' && !property.widget)
        return [];
    // Many-to-many relationship — FormControl holds `string[]` of FK ids.
    // Non-nullable means "at least one selection"; Angular's built-in
    // `Validators.required` rejects null but accepts `[]`, so pair it with
    // `arrayMinLengthValidator(1)` (hand-authored in @aurora/validators).
    if (property.relationship?.type === 'many-to-many') {
        return property.nullable
            ? []
            : ['Validators.required', 'arrayMinLengthValidator(1)'];
    }
    const validators = [];
    if (!property.nullable && property.type !== 'boolean') {
        validators.push('Validators.required');
    }
    if (property.maxLength) {
        validators.push(`Validators.maxLength(${property.maxLength})`);
    }
    if (property.minLength) {
        validators.push(`Validators.minLength(${property.minLength})`);
    }
    if (property.length !== undefined && property.length > 0) {
        validators.push(`Validators.minLength(${property.length})`, `Validators.maxLength(${property.length})`);
    }
    return validators;
}
