/*  Copyright (C) CZ.NIC, z.s.p.o. and contributors
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  For more information, see <https://www.knot-dns.cz/>
 */

#include "knot/common/log.h"
#include "knot/conf/conf.h"
#include "knot/dnssec/zone-events.h"
#include "knot/zone/zone.h"

int event_validate(conf_t *conf, zone_t *zone)
{
	assert(zone);

	if (zone_contents_is_empty(zone->contents)) {
		return KNOT_EEMPTYZONE;
	}

	zone_update_t fake_upd = {
		.zone = zone,
		.new_cont = zone->contents,
		// .validation_hint is zeroed
	};
	validation_conf_t val_conf = {
		.conf = conf,
		.now = knot_time(),
		.incremental = false,
		.fast = true, // they have been checked upon update, now only checking RRSIGs' expiration
		.log_plan = true,
	};

	if (zone_get_flag(zone, ZONE_FORCE_VALIDATE, true)) {
		val_conf.fast = false;
		val_conf.no_skip_crypto = true;
		log_zone_info(zone->name, "DNSSEC, full zone revalidation");
	} else {
		log_zone_info(zone->name, "DNSSEC, RRSIG expiration revalidation");
	}

	return knot_dnssec_validate_zone(&fake_upd, &val_conf);
}
