import {
  userRegistrationSchema,
  userLoginSchema,
  chatMessageSchema,
  prayerRequestSchema,
  bookmarkSchema,
  searchSchema,
  chapterSchema
} from '@/lib/validation'

describe('Validation Schemas', () => {
  describe('userRegistrationSchema', () => {
    it('should validate correct user registration data', () => {
      const validData = {
        email: 'test@example.com',
        password: 'Password123',
        name: 'Test User'
      }

      const result = userRegistrationSchema.safeParse(validData)
      expect(result.success).toBe(true)
    })

    it('should reject invalid email', () => {
      const invalidData = {
        email: 'invalid-email',
        password: 'Password123',
        name: 'Test User'
      }

      const result = userRegistrationSchema.safeParse(invalidData)
      expect(result.success).toBe(false)
    })

    it('should reject weak password', () => {
      const invalidData = {
        email: 'test@example.com',
        password: 'weak',
        name: 'Test User'
      }

      const result = userRegistrationSchema.safeParse(invalidData)
      expect(result.success).toBe(false)
    })
  })

  describe('chatMessageSchema', () => {
    it('should validate correct chat message data', () => {
      const validData = {
        messages: [
          { role: 'user', content: 'Hello' },
          { role: 'assistant', content: 'Hi there!' }
        ]
      }

      const result = chatMessageSchema.safeParse(validData)
      expect(result.success).toBe(true)
    })

    it('should reject empty messages array', () => {
      const invalidData = {
        messages: []
      }

      const result = chatMessageSchema.safeParse(invalidData)
      expect(result.success).toBe(false)
    })
  })

  describe('prayerRequestSchema', () => {
    it('should validate correct prayer request', () => {
      const validData = {
        content: 'Please pray for my family during this difficult time.',
        isAnonymous: true
      }

      const result = prayerRequestSchema.safeParse(validData)
      expect(result.success).toBe(true)
    })

    it('should reject too short prayer request', () => {
      const invalidData = {
        content: 'Short',
        isAnonymous: true
      }

      const result = prayerRequestSchema.safeParse(invalidData)
      expect(result.success).toBe(false)
    })
  })

  describe('searchSchema', () => {
    it('should validate correct search parameters', () => {
      const validData = {
        q: 'love',
        limit: 10
      }

      const result = searchSchema.safeParse(validData)
      expect(result.success).toBe(true)
    })

    it('should apply default limit', () => {
      const validData = {
        q: 'love'
      }

      const result = searchSchema.safeParse(validData)
      expect(result.success).toBe(true)
      if (result.success) {
        expect(result.data.limit).toBe(10)
      }
    })
  })

  describe('chapterSchema', () => {
    it('should validate correct chapter parameters', () => {
      const validData = {
        book: 1,
        chapter: 1
      }

      const result = chapterSchema.safeParse(validData)
      expect(result.success).toBe(true)
    })

    it('should reject invalid book ID', () => {
      const invalidData = {
        book: 0,
        chapter: 1
      }

      const result = chapterSchema.safeParse(invalidData)
      expect(result.success).toBe(false)
    })
  })
})