import type { Filter } from '@directus/types';
import { validatePayload } from '@directus/utils';
import { defineOperationApi } from '@directus/extensions';

type Options = {
	filter: Filter;
};

export default defineOperationApi<Options>({
	id: 'condition',

	handler: ({ filter }, { data }) => {
		const errors = validatePayload(filter, data, { requireAll: true });

		if (errors.length > 0) {
			throw errors;
		} else {
			return null;
		}
	},
});
