You are an expert code reviewer. Your task is to analyze the provided code files and provide a comprehensive code review. For each file, consider:

1. Code Quality: Assess readability, maintainability, and adherence to best practices
2. Potential Issues: Identify bugs, security vulnerabilities, or performance concerns
3. Suggestions: Provide specific recommendations for improvements

Format your review as follows:
1. Start with a brief overview of all files
2. For each file, provide:
   - A summary of the file's purpose
   - Key findings (both positive and negative)
   - Specific recommendations
3. End with any overall suggestions for the codebase

Your review should be detailed but concise, focusing on the most important aspects of the code.

Files to review:

File: src/core/schedule.ts
Content:
import { Cron as CronerJob } from 'croner'
import { Flashcore } from 'robo.js'
import { cronLogger } from './loggers'

interface CronJob extends CronerJob {
	save: (id?: string) => Promise<string>
}

interface CronJobData {
	schedule: string
	task: string | (() => void)
	type: 'file' | 'function'
}

const FLASHCORE_KEY = 'plugin-cron:'

export const Cron = (schedule: string, task: string | (() => void)): CronJob => {
	let job: CronJob

	if (typeof task === 'string') {
		// File-based job
		job = CronerJob(schedule, async () => {
			try {
				const module = await import(task)
				if (typeof module.default === 'function') {
					await module.default()
				} else {
					cronLogger.warn(`File ${task} does not export a default function`)
				}
			} catch (error) {
				cronLogger.error(`Error executing file-based job: ${task}`, error)
			}
		}) as CronJob
	} else {
		// JavaScript API job
		job = CronerJob(schedule, task) as CronJob
	}

	job.save = async (id?: string) => {
		const jobId = id || `job_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
		const jobData: CronJobData = {
			schedule,
			task: typeof task === 'string' ? task : task.toString(),
			type: typeof task === 'string' ? 'file' : 'function'
		}

		await Flashcore.set<CronJobData>(`${FLASHCORE_KEY}${jobId}`, jobData)

		const jobIds = (await Flashcore.get<string[]>('*', { namespace: 'cron-jobs' })) || []
		if (!jobIds.includes(jobId)) {
			jobIds.push(jobId)
			await Flashcore.set('*', jobIds, { namespace: 'cron-jobs' })
		}

		Cron.jobs.set(jobId, job)

		return jobId
	}

	return job
}

Cron.jobs = new Map<string, CronJob>()

Cron.remove = async (id: string): Promise<void> => {
	const job = Cron.jobs.get(id)
	if (job) {
		job.stop()
		Cron.jobs.delete(id)
		await Flashcore.delete(`${FLASHCORE_KEY}${id}`)

		const jobIds = (await Flashcore.get<string[]>('*', { namespace: 'cron-jobs' })) || []
		const updatedJobIds = jobIds.filter((jobId) => jobId !== id)
		await Flashcore.set('*', updatedJobIds, { namespace: 'cron-jobs' })
	}
}

Cron.restoreJobs = async (): Promise<void> => {
	try {
		const jobIds = await Flashcore.get<string[]>('*', { namespace: 'cron-jobs' })

		if (!jobIds || !Array.isArray(jobIds)) {
			cronLogger.warn('No valid job IDs found to restore')
			return
		}

		for (const jobId of jobIds) {
			try {
				const jobData = await Flashcore.get<CronJobData>(`${FLASHCORE_KEY}${jobId}`)
				if (jobData && typeof jobData === 'object') {
					if (
						typeof jobData.schedule === 'string' &&
						(typeof jobData.task === 'string' || typeof jobData.task === 'function')
					) {
						let task: string | (() => void)
						if (jobData.type === 'file') {
							task = jobData.task as string
						} else {
							task = new Function('return ' + jobData.task)() as () => void
						}
						const job = Cron(jobData.schedule, task)
						Cron.jobs.set(jobId, job)
						cronLogger.debug(`Restored job ${jobId}: ${jobData.schedule} ${jobData.type}`)
					} else {
						throw new Error('Invalid job data structure')
					}
				} else {
					throw new Error('Job data not found or invalid')
				}
			} catch (error) {
				cronLogger.warn(`Failed to restore job ${jobId}:`, error)
			}
		}
	} catch (error) {
		cronLogger.error('Error restoring cron jobs:', error)
		throw error
	}
}



PROMPT: You are an expert code reviewer. Your task is to analyze the provided code files and provide a comprehensive code review. For each file, consider:

1. Code Quality: Assess readability, maintainability, and adherence to best practices
2. Potential Issues: Identify bugs, security vulnerabilities, or performance concerns
3. Suggestions: Provide specific recommendations for improvements

Format your review as follows:
1. Start with a brief overview of all files
2. For each file, provide:
   - A summary of the file's purpose
   - Key findings (both positive and negative)
   - Specific recommendations
3. End with any overall suggestions for the codebase

Your review should be detailed but concise, focusing on the most important aspects of the code.

Files to review:

File: src/core/schedule.ts
Content:
import { Cron as CronerJob } from 'croner'
import { Flashcore } from 'robo.js'
import { cronLogger } from './loggers'

interface CronJob extends CronerJob {
	save: (id?: string) => Promise<string>
}

interface CronJobData {
	schedule: string
	task: string | (() => void)
	type: 'file' | 'function'
}

const FLASHCORE_KEY = 'plugin-cron:'

export const Cron = (schedule: string, task: string | (() => void)): CronJob => {
	let job: CronJob

	if (typeof task === 'string') {
		// File-based job
		job = CronerJob(schedule, async () => {
			try {
				const module = await import(task)
				if (typeof module.default === 'function') {
					await module.default()
				} else {
					cronLogger.warn(`File ${task} does not export a default function`)
				}
			} catch (error) {
				cronLogger.error(`Error executing file-based job: ${task}`, error)
			}
		}) as CronJob
	} else {
		// JavaScript API job
		job = CronerJob(schedule, task) as CronJob
	}

	job.save = async (id?: string) => {
		const jobId = id || `job_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
		const jobData: CronJobData = {
			schedule,
			task: typeof task === 'string' ? task : task.toString(),
			type: typeof task === 'string' ? 'file' : 'function'
		}

		await Flashcore.set<CronJobData>(`${FLASHCORE_KEY}${jobId}`, jobData)

		const jobIds = (await Flashcore.get<string[]>('*', { namespace: 'cron-jobs' })) || []
		if (!jobIds.includes(jobId)) {
			jobIds.push(jobId)
			await Flashcore.set('*', jobIds, { namespace: 'cron-jobs' })
		}

		Cron.jobs.set(jobId, job)

		return jobId
	}

	return job
}

Cron.jobs = new Map<string, CronJob>()

Cron.remove = async (id: string): Promise<void> => {
	const job = Cron.jobs.get(id)
	if (job) {
		job.stop()
		Cron.jobs.delete(id)
		await Flashcore.delete(`${FLASHCORE_KEY}${id}`)

		const jobIds = (await Flashcore.get<string[]>('*', { namespace: 'cron-jobs' })) || []
		const updatedJobIds = jobIds.filter((jobId) => jobId !== id)
		await Flashcore.set('*', updatedJobIds, { namespace: 'cron-jobs' })
	}
}

Cron.restoreJobs = async (): Promise<void> => {
	try {
		const jobIds = await Flashcore.get<string[]>('*', { namespace: 'cron-jobs' })

		if (!jobIds || !Array.isArray(jobIds)) {
			cronLogger.warn('No valid job IDs found to restore')
			return
		}

		for (const jobId of jobIds) {
			try {
				const jobData = await Flashcore.get<CronJobData>(`${FLASHCORE_KEY}${jobId}`)
				if (jobData && typeof jobData === 'object') {
					if (
						typeof jobData.schedule === 'string' &&
						(typeof jobData.task === 'string' || typeof jobData.task === 'function')
					) {
						let task: string | (() => void)
						if (jobData.type === 'file') {
							task = jobData.task as string
						} else {
							task = new Function('return ' + jobData.task)() as () => void
						}
						const job = Cron(jobData.schedule, task)
						Cron.jobs.set(jobId, job)
						cronLogger.debug(`Restored job ${jobId}: ${jobData.schedule} ${jobData.type}`)
					} else {
						throw new Error('Invalid job data structure')
					}
				} else {
					throw new Error('Job data not found or invalid')
				}
			} catch (error) {
				cronLogger.warn(`Failed to restore job ${jobId}:`, error)
			}
		}
	} catch (error) {
		cronLogger.error('Error restoring cron jobs:', error)
		throw error
	}
}