import { describe, it, expect } from 'vitest'
import { resolveProductSwitchTarget } from '@/lib/product-switch-path'

describe('resolveProductSwitchTarget', () => {
  it('returns null for non-product pages', () => {
    expect(resolveProductSwitchTarget('/dashboard', 'new-id')).toBeNull()
    expect(resolveProductSwitchTarget('/insights', 'new-id')).toBeNull()
    expect(resolveProductSwitchTarget('/ideas', 'new-id')).toBeNull()
    expect(resolveProductSwitchTarget('/jobs', 'new-id')).toBeNull()
    expect(resolveProductSwitchTarget('/', 'new-id')).toBeNull()
  })

  it('maps /products/<old> to /products/<new>', () => {
    expect(resolveProductSwitchTarget('/products/old-id', 'new-id')).toBe('/products/new-id')
  })

  it('maps /products/<old>/ to /products/<new>', () => {
    expect(resolveProductSwitchTarget('/products/old-id/', 'new-id')).toBe('/products/new-id')
  })

  it('maps /products/<old>/sprint to /products/<new>/sprint', () => {
    expect(resolveProductSwitchTarget('/products/old-id/sprint', 'new-id')).toBe(
      '/products/new-id/sprint',
    )
  })

  it('maps /products/<old>/sprint/<sprintId> to /products/<new>/sprint', () => {
    expect(resolveProductSwitchTarget('/products/old-id/sprint/abc123', 'new-id')).toBe(
      '/products/new-id/sprint',
    )
  })

  it('maps /products/<old>/sprint/.../planning to /products/<new>/sprint', () => {
    expect(resolveProductSwitchTarget('/products/old-id/sprint/abc123/planning', 'new-id')).toBe(
      '/products/new-id/sprint',
    )
  })

  it('maps /products/<old>/solo to /products/<new>/solo', () => {
    expect(resolveProductSwitchTarget('/products/old-id/solo', 'new-id')).toBe(
      '/products/new-id/solo',
    )
  })

  it('falls back to /products/<new> for /products/<old>/settings', () => {
    expect(resolveProductSwitchTarget('/products/old-id/settings', 'new-id')).toBe(
      '/products/new-id',
    )
  })

  it('falls back to /products/<new> for unknown sub-segments', () => {
    expect(resolveProductSwitchTarget('/products/old-id/unknown/deep', 'new-id')).toBe(
      '/products/new-id',
    )
  })
})
