import { describe, it, expect } from 'vitest'
import { updatePreferencesSchema } from './preferences'

describe('Preferences Validation Schemas', () => {
  describe('updatePreferencesSchema', () => {
    it('should validate correct preferences data', () => {
      const result = updatePreferencesSchema.safeParse({
        characterDisplay: 'SIMPLIFIED',
        cardsPerSession: 20,
        dailyGoal: 50,
        transcriptionType: 'pinyin',
        removalThreshold: 10,
        allowManualDifficulty: true,
      })
      expect(result.success).toBe(true)
    })

    it('should validate TRADITIONAL character display', () => {
      const result = updatePreferencesSchema.safeParse({
        characterDisplay: 'TRADITIONAL',
      })
      expect(result.success).toBe(true)
    })

    it('should validate BOTH character display', () => {
      const result = updatePreferencesSchema.safeParse({
        characterDisplay: 'BOTH',
      })
      expect(result.success).toBe(true)
    })

    it('should reject invalid character display', () => {
      const result = updatePreferencesSchema.safeParse({
        characterDisplay: 'INVALID',
      })
      expect(result.success).toBe(false)
    })

    it('should reject cardsPerSession below 5', () => {
      const result = updatePreferencesSchema.safeParse({
        cardsPerSession: 4,
      })
      expect(result.success).toBe(false)
    })

    it('should accept cardsPerSession of 5 (minimum)', () => {
      const result = updatePreferencesSchema.safeParse({
        cardsPerSession: 5,
      })
      expect(result.success).toBe(true)
    })

    it('should reject dailyGoal below 10', () => {
      const result = updatePreferencesSchema.safeParse({
        dailyGoal: 9,
      })
      expect(result.success).toBe(false)
    })

    it('should accept dailyGoal of 10 (minimum)', () => {
      const result = updatePreferencesSchema.safeParse({
        dailyGoal: 10,
      })
      expect(result.success).toBe(true)
    })

    it('should accept cardsPerSession of 100 (maximum)', () => {
      const result = updatePreferencesSchema.safeParse({
        cardsPerSession: 100,
      })
      expect(result.success).toBe(true)
    })

    it('should accept dailyGoal of 500 (maximum)', () => {
      const result = updatePreferencesSchema.safeParse({
        dailyGoal: 500,
      })
      expect(result.success).toBe(true)
    })

    it('should reject cardsPerSession above 100', () => {
      const result = updatePreferencesSchema.safeParse({
        cardsPerSession: 101,
      })
      expect(result.success).toBe(false)
    })

    it('should reject dailyGoal above 500', () => {
      const result = updatePreferencesSchema.safeParse({
        dailyGoal: 501,
      })
      expect(result.success).toBe(false)
    })

    it('should accept empty object (no updates)', () => {
      const result = updatePreferencesSchema.safeParse({})
      expect(result.success).toBe(true)
    })

    it('should validate partial updates', () => {
      const result = updatePreferencesSchema.safeParse({
        cardsPerSession: 30,
      })
      expect(result.success).toBe(true)
    })

    it('should accept preferredLanguageId as string', () => {
      const result = updatePreferencesSchema.safeParse({
        preferredLanguageId: 'some-uuid-string',
      })
      expect(result.success).toBe(true)
    })

    it('should reject removalThreshold below 5', () => {
      const result = updatePreferencesSchema.safeParse({
        removalThreshold: 4,
      })
      expect(result.success).toBe(false)
    })

    it('should accept removalThreshold of 5 (minimum)', () => {
      const result = updatePreferencesSchema.safeParse({
        removalThreshold: 5,
      })
      expect(result.success).toBe(true)
    })

    it('should accept removalThreshold of 50 (maximum)', () => {
      const result = updatePreferencesSchema.safeParse({
        removalThreshold: 50,
      })
      expect(result.success).toBe(true)
    })

    it('should reject removalThreshold above 50', () => {
      const result = updatePreferencesSchema.safeParse({
        removalThreshold: 51,
      })
      expect(result.success).toBe(false)
    })

    it('should validate boolean allowManualDifficulty', () => {
      const result = updatePreferencesSchema.safeParse({
        allowManualDifficulty: false,
      })
      expect(result.success).toBe(true)
    })

    it('should validate different transcription types', () => {
      const types = ['pinyin', 'zhuyin', 'wade-giles', 'ipa']
      types.forEach((type) => {
        const result = updatePreferencesSchema.safeParse({
          transcriptionType: type,
        })
        expect(result.success).toBe(true)
      })
    })
  })
})
