import { describe, it, expect } from 'vitest'
import { COLLECTIONS, FEATURED_COLLECTION_ID } from '../../shared/data/collections'

describe('collections data', () => {
  describe('COLLECTIONS structure', () => {
    it('should have exactly 6 collections', () => {
      expect(COLLECTIONS).toHaveLength(6)
    })

    it('should have all required properties', () => {
      COLLECTIONS.forEach(collection => {
        expect(collection.id).toBeDefined()
        expect(collection.title).toBeDefined()
        expect(collection.description).toBeDefined()
        expect(collection.icon).toBeDefined()
        expect(collection.workoutIds).toBeDefined()
        expect(Array.isArray(collection.workoutIds)).toBe(true)
      })
    })

    it('should have unique collection IDs', () => {
      const ids = COLLECTIONS.map(c => c.id)
      const uniqueIds = new Set(ids)
      expect(uniqueIds.size).toBe(ids.length)
    })

    it('should have unique collection titles', () => {
      const titles = COLLECTIONS.map(c => c.title)
      const uniqueTitles = new Set(titles)
      expect(uniqueTitles.size).toBe(titles.length)
    })

    it('should have at least one workout per collection', () => {
      COLLECTIONS.forEach(collection => {
        expect(collection.workoutIds.length).toBeGreaterThan(0)
      })
    })
  })

  describe('specific collections', () => {
    it('should have Morning Energizer collection', () => {
      const collection = COLLECTIONS.find(c => c.id === 'morning-energizer')
      expect(collection).toBeDefined()
      expect(collection!.title).toBe('Morning Energizer')
      expect(collection!.icon).toBe('🌅')
      expect(collection!.workoutIds).toHaveLength(5)
    })

    it('should have No Equipment collection', () => {
      const collection = COLLECTIONS.find(c => c.id === 'no-equipment')
      expect(collection).toBeDefined()
      expect(collection!.title).toBe('No Equipment')
      expect(collection!.workoutIds.length).toBeGreaterThan(10)
    })

    it('should have 7-Day Burn Challenge collection', () => {
      const collection = COLLECTIONS.find(c => c.id === '7-day-burn')
      expect(collection).toBeDefined()
      expect(collection!.title).toBe('7-Day Burn Challenge')
      expect(collection!.workoutIds).toHaveLength(7)
      expect(collection!.gradient).toBeDefined()
    })

    it('should have Quick & Intense collection', () => {
      const collection = COLLECTIONS.find(c => c.id === 'quick-intense')
      expect(collection).toBeDefined()
      expect(collection!.title).toBe('Quick & Intense')
      expect(collection!.workoutIds.length).toBeGreaterThan(5)
    })

    it('should have Core Focus collection', () => {
      const collection = COLLECTIONS.find(c => c.id === 'core-focus')
      expect(collection).toBeDefined()
      expect(collection!.title).toBe('Core Focus')
      expect(collection!.workoutIds).toHaveLength(6)
    })

    it('should have Leg Day collection', () => {
      const collection = COLLECTIONS.find(c => c.id === 'leg-day')
      expect(collection).toBeDefined()
      expect(collection!.title).toBe('Leg Day')
      expect(collection!.workoutIds).toHaveLength(7)
    })
  })

  describe('FEATURED_COLLECTION_ID', () => {
    it('should reference 7-day-burn', () => {
      expect(FEATURED_COLLECTION_ID).toBe('7-day-burn')
    })

    it('should reference an existing collection', () => {
      const featured = COLLECTIONS.find(c => c.id === FEATURED_COLLECTION_ID)
      expect(featured).toBeDefined()
    })
  })

  describe('collection gradients', () => {
    it('should have gradient on 7-day-burn', () => {
      const collection = COLLECTIONS.find(c => c.id === '7-day-burn')
      expect(collection!.gradient).toBeDefined()
      expect(collection!.gradient).toHaveLength(2)
    })

    it('should have valid hex colors in gradient', () => {
      const hexPattern = /^#[0-9A-Fa-f]{6}$/
      const collection = COLLECTIONS.find(c => c.gradient)
      if (collection?.gradient) {
        collection.gradient.forEach(color => {
          expect(color).toMatch(hexPattern)
        })
      }
    })
  })

  describe('workout ID format', () => {
    it('should have string workout IDs', () => {
      COLLECTIONS.forEach(collection => {
        collection.workoutIds.forEach(id => {
          expect(typeof id).toBe('string')
        })
      })
    })

    it('should have numeric-like workout IDs', () => {
      const numericPattern = /^\d+$/
      COLLECTIONS.forEach(collection => {
        collection.workoutIds.forEach(id => {
          expect(id).toMatch(numericPattern)
        })
      })
    })
  })
})
