import { Portfolio } from '../index'

describe('Portfolio Collection', () => {
  it('should have correct slug', () => {
    expect(Portfolio.slug).toBe('portfolio')
  })

  it('should have all required fields', () => {
    const fieldNames = Portfolio.fields.map((f) => ('name' in f ? f.name : null))
    expect(fieldNames).toContain('title')
    expect(fieldNames).toContain('slug')
    expect(fieldNames).toContain('url')
    expect(fieldNames).toContain('image')
    expect(fieldNames).toContain('description')
    expect(fieldNames).toContain('websiteType')
    expect(fieldNames).toContain('tags')
  })

  it('should have correct access control', () => {
    expect(Portfolio.access.read).toBeDefined()
    expect(Portfolio.access.create).toBeDefined()
    expect(Portfolio.access.update).toBeDefined()
    expect(Portfolio.access.delete).toBeDefined()
  })

  it('should have admin configuration', () => {
    expect(Portfolio.admin).toBeDefined()
    expect(Portfolio.admin?.useAsTitle).toBe('title')
    expect(Portfolio.admin?.defaultColumns).toEqual(['title', 'websiteType', 'updatedAt'])
  })

  it('should have websiteType field with correct options', () => {
    const websiteTypeField = Portfolio.fields.find((f) => f.name === 'websiteType')
    expect(websiteTypeField).toBeDefined()
    expect(websiteTypeField?.type).toBe('select')
    if (websiteTypeField?.type === 'select') {
      const optionValues = websiteTypeField.options.map((o) => o.value)
      expect(optionValues).toContain('corporate')
      expect(optionValues).toContain('ecommerce')
      expect(optionValues).toContain('landing')
      expect(optionValues).toContain('brand')
      expect(optionValues).toContain('other')
    }
  })

  it('should have tags field as array', () => {
    const tagsField = Portfolio.fields.find((f) => f.name === 'tags')
    expect(tagsField).toBeDefined()
    expect(tagsField?.type).toBe('array')
  })

  it('should have image field with relation to media', () => {
    const imageField = Portfolio.fields.find((f) => f.name === 'image')
    expect(imageField).toBeDefined()
    expect(imageField?.type).toBe('upload')
    if (imageField?.type === 'upload') {
      expect(imageField.relationTo).toBe('media')
    }
  })
})
