import { create } from "zustand";

type LastScan = {
	terminalId?: string;
	screen?: string;
	prompt?: string;
	message?: string;
	status: "success" | "error" | "location" | "unknown";
	lines?: string[];
	timestamp?: number;
};

type ScannerStore = {
	lastScan: LastScan | null;
	setLastScan: (scan: LastScan | null) => void;
	clearLastScan: () => void;
};

export const useScannerStore = create<ScannerStore>((set) => ({
	lastScan: null,

	setLastScan: (scan) =>
		set({
			lastScan: scan
				? {
						...scan,
						timestamp: Date.now(),
					}
				: null,
		}),

	clearLastScan: () => set({ lastScan: null }),
}));
