/**
 * Unit tests for settings module — types + validation.
 */

import { describe, it, expect } from 'vitest';
import { SetDeviceOverridesSchema, UpdateSettingsSchema } from './types.js';

describe('UpdateSettingsSchema', () => {
  it('accepts generic settings payload', () => {
    const result = UpdateSettingsSchema.safeParse({
      settings: {
        hotkey: 'fn',
        language: 'en-US',
        cleanup_enabled: true,
        custom_vocabulary: ['alpha', 'beta'],
      },
    });
    expect(result.success).toBe(true);
  });

  it('rejects missing settings object', () => {
    const result = UpdateSettingsSchema.safeParse({});
    expect(result.success).toBe(false);
  });
});

describe('SetDeviceOverridesSchema', () => {
  it('accepts per-device overrides payload', () => {
    const result = SetDeviceOverridesSchema.safeParse({
      overrides: {
        language: 'en-GB',
        sound_enabled: false,
      },
    });
    expect(result.success).toBe(true);
  });

  it('rejects missing overrides object', () => {
    const result = SetDeviceOverridesSchema.safeParse({});
    expect(result.success).toBe(false);
  });
});

describe('settingsRoutes export', () => {
  it('exports settingsRoutes function', async () => {
    const mod = await import('./routes.js');
    expect(typeof mod.settingsRoutes).toBe('function');
  });
});
