import { AuditStrategy, SystemAuditParams, EntityChangeParams } from './auditStrategyService';
import { SystemAuditLog } from '#models/SystemAuditLog';
import { EntityChangeLog } from '#models/EntityChangeLog';
import { randomUUID } from 'crypto';

export class DirectAuditStrategy implements AuditStrategy {
	async logSystemAudit(params: SystemAuditParams): Promise<void> {
		await SystemAuditLog.create({
			id: randomUUID(),
			outbox_event_id: randomUUID(),
			request_id: randomUUID(),
			trace_id: randomUUID(),
			action: params.action,
			module: params.module,
			actor_name: params.actor_name,
			actor_id: params.actor_id,
			severity: params.severity || 'LOW',
			created_at: new Date(),
		});
	}

	async logEntityChange(params: EntityChangeParams): Promise<void> {
		await EntityChangeLog.create({
			id: randomUUID(),
			outbox_event_id: randomUUID(),
			request_id: randomUUID(),
			trace_id: randomUUID(),
			entity_type: params.entity_type,
			entity_id: params.entity_id,
			change_type: params.change_type,
			actor_name: params.actor_name,
			actor_id: params.actor_id,
			actor_email: params.actor_email,
			payload: params.changes || {},
			created_at: new Date(),
		});
	}
}
