import { describe, expect, it } from 'vitest';
import {
  GuildGeneralSettingsPatchSchema,
  ModulesUpdateSchema,
  hasManageGuildPermission,
  DashboardAccessRulesUpdateSchema
} from './phase6.js';

describe('phase6 schemas', () => {
  it('accepts general settings patches', () => {
    const parsed = GuildGeneralSettingsPatchSchema.parse({
      locale: 'en',
      timezone: 'UTC'
    });
    expect(parsed.locale).toBe('en');
    expect(parsed.timezone).toBe('UTC');
  });

  it('rejects empty general settings patches', () => {
    expect(() => GuildGeneralSettingsPatchSchema.parse({})).toThrow();
  });

  it('validates module updates', () => {
    const parsed = ModulesUpdateSchema.parse({
      modules: { moderation: true, automod: false }
    });
    expect(parsed.modules.moderation).toBe(true);
    expect(parsed.modules.automod).toBe(false);
  });

  it('detects manage guild permission', () => {
    expect(hasManageGuildPermission('32')).toBe(true);
    expect(hasManageGuildPermission('0')).toBe(false);
    expect(hasManageGuildPermission(String(32n | 8n))).toBe(true);
  });

  it('validates access rules', () => {
    const parsed = DashboardAccessRulesUpdateSchema.parse({
      rules: [{ roleId: '123456789012345678', modules: 'all' }]
    });
    expect(parsed.rules).toHaveLength(1);
  });
});
