import { describe, it, expect } from 'vitest';
import { PluginError } from '../core/plugin-types';
import type { CanvasPlugin, PluginContext, PluginRegistration, PluginErrorCode } from '../core/plugin-types';

describe('plugin-types', () => {
	describe('PluginError', () => {
		it('constructs with message, pluginId, and code', () => {
			const err = new PluginError('Already exists', 'my-plugin', 'ALREADY_REGISTERED');
			expect(err.message).toContain('my-plugin');
			expect(err.message).toContain('Already exists');
			expect(err.pluginId).toBe('my-plugin');
			expect(err.code).toBe('ALREADY_REGISTERED');
		});

		it('is an instance of Error', () => {
			const err = new PluginError('test', 'p1', 'NOT_FOUND');
			expect(err).toBeInstanceOf(Error);
		});

		it('has name set to PluginError', () => {
			const err = new PluginError('test', 'p1', 'CONFLICT');
			expect(err.name).toBe('PluginError');
		});
	});

	describe('CanvasPlugin interface shape', () => {
		it('accepts a minimal plugin definition', () => {
			const plugin: CanvasPlugin = {
				id: 'test-plugin',
				name: 'Test Plugin',
			};
			expect(plugin.id).toBe('test-plugin');
			expect(plugin.nodeTypes).toBeUndefined();
			expect(plugin.commands).toBeUndefined();
		});

		it('accepts a full plugin definition', () => {
			const plugin: CanvasPlugin = {
				id: 'full',
				name: 'Full Plugin',
				version: '1.0.0',
				dependencies: ['dep-a'],
				nodeTypes: {},
				commands: [],
				actions: [],
			};
			expect(plugin.dependencies).toEqual(['dep-a']);
		});
	});
});
