import { describe, expect, it } from 'vitest';
import {
  DEFAULT_PREMIUM_TIER_CONFIGS,
  GuildPremiumAssignSchema,
  isAssignmentActive,
  limitKeyForResource,
  PremiumTierConfigSchema
} from './premium.js';

describe('premium schemas', () => {
  it('parses default free config', () => {
    const parsed = PremiumTierConfigSchema.parse(DEFAULT_PREMIUM_TIER_CONFIGS.FREE);
    expect(parsed.maxTags).toBe(15);
    expect(parsed.features.feeds).toBe(true);
  });

  it('maps resources to limit keys', () => {
    expect(limitKeyForResource('tags')).toBe('maxTags');
    expect(limitKeyForResource('backups')).toBe('maxBackups');
  });

  it('validates guild assignment and expiry', () => {
    expect(
      GuildPremiumAssignSchema.parse({
        guildId: '123456789012345678',
        tier: 'PREMIUM',
        note: null,
        expiresAt: null
      }).tier
    ).toBe('PREMIUM');
    expect(isAssignmentActive(null)).toBe(true);
    expect(isAssignmentActive(new Date(Date.now() - 1000))).toBe(false);
    expect(isAssignmentActive(new Date(Date.now() + 60_000))).toBe(true);
  });
});
