// #region RoutesRegistryTest [C:2] [TYPE Module] [SEMANTICS test, routes, navigation, registry]
// @BRIEF Unit tests for ROUTES route builders — verifies all patterns return correct URLs.
// @LAYER Tests
// @RELATION BINDS_TO -> [RoutesRegistry]
// @TEST_CONTRACT: home returns '/'
// @TEST_CONTRACT: login returns '/login'
// @TEST_CONTRACT: Dynamic param routes encode params correctly
// @TEST_CONTRACT: Optional param routes work with and without params
import { describe, it, expect } from 'vitest';
import { ROUTES } from '$lib/routes';

describe('ROUTES — static routes', () => {
	it('home returns "/"', () => {
		expect(ROUTES.home()).toBe('/');
	});

	it('login returns "/login"', () => {
		expect(ROUTES.login()).toBe('/login');
	});

	it('profile returns "/profile"', () => {
		expect(ROUTES.profile()).toBe('/profile');
	});

	it('maintenance returns "/maintenance"', () => {
		expect(ROUTES.maintenance()).toBe('/maintenance');
	});
});

describe('ROUTES — dashboards', () => {
	it('dashboards.list returns "/dashboards" without envId', () => {
		expect(ROUTES.dashboards.list()).toBe('/dashboards');
	});

	it('dashboards.list returns "/dashboards?env_id=..." with envId', () => {
		expect(ROUTES.dashboards.list('prod-1')).toBe('/dashboards?env_id=prod-1');
	});

	it('dashboards.list encodes envId', () => {
		expect(ROUTES.dashboards.list('my env')).toBe('/dashboards?env_id=my%20env');
	});

	it('dashboards.detail returns correct path', () => {
		expect(ROUTES.dashboards.detail(42, 'env-1')).toBe('/dashboards/42?env_id=env-1');
	});

	it('dashboards.validation returns correct path', () => {
		expect(ROUTES.dashboards.validation('abc', 'env-x')).toBe('/dashboards/abc/validation?env_id=env-x');
	});

	it('dashboards.health returns "/dashboards/health"', () => {
		expect(ROUTES.dashboards.health()).toBe('/dashboards/health');
	});
});

describe('ROUTES — datasets', () => {
	it('datasets.list returns "/datasets" without envId', () => {
		expect(ROUTES.datasets.list()).toBe('/datasets');
	});

	it('datasets.list returns "/datasets?env_id=..." with envId', () => {
		expect(ROUTES.datasets.list('staging')).toBe('/datasets?env_id=staging');
	});

	it('datasets.detail returns correct path', () => {
		expect(ROUTES.datasets.detail(7, 'env-2')).toBe('/datasets/7?env_id=env-2');
	});

	it('datasets.review.list returns "/datasets/review"', () => {
		expect(ROUTES.datasets.review.list()).toBe('/datasets/review');
	});

	it('datasets.review.workspace returns correct path', () => {
		expect(ROUTES.datasets.review.workspace('session-1')).toBe('/datasets/review/session-1');
	});
});

describe('ROUTES — migration', () => {
	it('migration.overview returns "/migration"', () => {
		expect(ROUTES.migration.overview()).toBe('/migration');
	});

	it('migration.mappings returns "/migration/mappings"', () => {
		expect(ROUTES.migration.mappings()).toBe('/migration/mappings');
	});
});

describe('ROUTES — git', () => {
	it('git.status returns "/git"', () => {
		expect(ROUTES.git.status()).toBe('/git');
	});
});

describe('ROUTES — translate', () => {
	it('translate.list returns "/translate"', () => {
		expect(ROUTES.translate.list()).toBe('/translate');
	});

	it('translate.new returns "/translate/new"', () => {
		expect(ROUTES.translate.new()).toBe('/translate/new');
	});

	it('translate.detail encodes id', () => {
		expect(ROUTES.translate.detail(99)).toBe('/translate/99');
	});

	it('translate.dictionaries.list returns "/translate/dictionaries"', () => {
		expect(ROUTES.translate.dictionaries.list()).toBe('/translate/dictionaries');
	});

	it('translate.dictionaries.detail encodes id', () => {
		expect(ROUTES.translate.dictionaries.detail('dict-1')).toBe('/translate/dictionaries/dict-1');
	});

	it('translate.history returns "/translate/history"', () => {
		expect(ROUTES.translate.history()).toBe('/translate/history');
	});
});

describe('ROUTES — validation tasks', () => {
	it('validationTasks.list returns "/validation-tasks" without search', () => {
		expect(ROUTES.validationTasks.list()).toBe('/validation-tasks');
	});

	it('validationTasks.list returns "/validation-tasks?search=..." with search', () => {
		expect(ROUTES.validationTasks.list('my query')).toBe('/validation-tasks?search=my%20query');
	});

	it('validationTasks.new returns "/validation-tasks/new" without ids', () => {
		expect(ROUTES.validationTasks.new()).toBe('/validation-tasks/new');
	});

	it('validationTasks.new returns "/validation-tasks/new?ids=..." with ids', () => {
		expect(ROUTES.validationTasks.new([1, 2, 3])).toBe('/validation-tasks/new?ids=1,2,3');
	});

	it('validationTasks.detail encodes policyId', () => {
		expect(ROUTES.validationTasks.detail('policy-1')).toBe('/validation-tasks/policy-1');
	});

	it('validationTasks.edit encodes policyId', () => {
		expect(ROUTES.validationTasks.edit('policy-1')).toBe('/validation-tasks/policy-1/edit');
	});

	it('validationTasks.runReport encodes policyId and runId', () => {
		expect(ROUTES.validationTasks.runReport('p1', 'run-1')).toBe('/validation-tasks/p1/runs/run-1');
	});

	it('validationTasks.history returns "/validation-tasks/history"', () => {
		expect(ROUTES.validationTasks.history()).toBe('/validation-tasks/history');
	});
});

describe('ROUTES — reports', () => {
	it('reports.list returns "/reports"', () => {
		expect(ROUTES.reports.list()).toBe('/reports');
	});

	it('reports.llmReport encodes taskId', () => {
		expect(ROUTES.reports.llmReport('task-1')).toBe('/reports/llm/task-1');
	});
});

describe('ROUTES — settings', () => {
	it('settings.general returns "/settings"', () => {
		expect(ROUTES.settings.general()).toBe('/settings');
	});

	it('settings.environmentsTab returns correct path', () => {
		expect(ROUTES.settings.environmentsTab()).toBe('/settings?tab=environments#environments');
	});

	it('settings.git returns "/settings/git"', () => {
		expect(ROUTES.settings.git()).toBe('/settings/git');
	});

	it('settings.automation returns "/settings/automation"', () => {
		expect(ROUTES.settings.automation()).toBe('/settings/automation');
	});

	it('settings.notifications returns "/settings/notifications"', () => {
		expect(ROUTES.settings.notifications()).toBe('/settings/notifications');
	});
});

describe('ROUTES — admin', () => {
	it('admin.overview returns "/admin"', () => {
		expect(ROUTES.admin.overview()).toBe('/admin');
	});

	it('admin.users returns "/admin/users"', () => {
		expect(ROUTES.admin.users()).toBe('/admin/users');
	});

	it('admin.roles returns "/admin/roles"', () => {
		expect(ROUTES.admin.roles()).toBe('/admin/roles');
	});

	it('admin.settings returns "/admin/settings"', () => {
		expect(ROUTES.admin.settings()).toBe('/admin/settings');
	});

	it('admin.llmSettings returns "/admin/settings/llm"', () => {
		expect(ROUTES.admin.llmSettings()).toBe('/admin/settings/llm');
	});
});

describe('ROUTES — storage', () => {
	it('storage.overview returns "/storage"', () => {
		expect(ROUTES.storage.overview()).toBe('/storage');
	});

	it('storage.backups returns "/storage/backups"', () => {
		expect(ROUTES.storage.backups()).toBe('/storage/backups');
	});
});

describe('ROUTES — tools', () => {
	it('tools.overview returns "/tools"', () => {
		expect(ROUTES.tools.overview()).toBe('/tools');
	});

	it('tools.mapper returns "/tools/mapper"', () => {
		expect(ROUTES.tools.mapper()).toBe('/tools/mapper');
	});

	it('tools.debug returns "/tools/debug"', () => {
		expect(ROUTES.tools.debug()).toBe('/tools/debug');
	});

	it('tools.storage returns "/tools/storage"', () => {
		expect(ROUTES.tools.storage()).toBe('/tools/storage');
	});

	it('tools.backups returns "/tools/backups"', () => {
		expect(ROUTES.tools.backups()).toBe('/tools/backups');
	});
});

describe('ROUTES — dynamic route encoding', () => {
	it('encodes special characters in params', () => {
		expect(ROUTES.translate.detail('a/b')).toBe('/translate/a%2Fb');
		expect(ROUTES.dashboards.detail('a b', 'env')).toBe('/dashboards/a%20b?env_id=env');
	});
});
// #endregion RoutesRegistryTest
