import { describe, expect, it } from 'vitest';
import { selectAddonKeyForScope } from '../addons';
import type { EventAddonCatalogItem } from '../../api';

const sampleAddons: EventAddonCatalogItem[] = [
  { key: 'extra_photos_500', label: '500 photos', price_id: 'price_1' },
  { key: 'extend_gallery_30d', label: '30 days', price_id: 'price_2' },
  { key: 'custom_photos', label: 'Custom photos', price_id: 'price_3' },
];

describe('selectAddonKeyForScope', () => {
  it('prefers scoped default with price id', () => {
    expect(selectAddonKeyForScope(sampleAddons, 'photos')).toBe('extra_photos_500');
    expect(selectAddonKeyForScope(sampleAddons, 'gallery')).toBe('extend_gallery_30d');
  });

  it('falls back to first scoped addon when defaults missing', () => {
    const addons: EventAddonCatalogItem[] = [{ key: 'custom_gallery', label: 'Gallery', price_id: 'price_9' }];
    expect(selectAddonKeyForScope(addons, 'gallery')).toBe('custom_gallery');
  });

  it('returns fallback key when no priced addons exist', () => {
    const addons: EventAddonCatalogItem[] = [{ key: 'extra_photos_500', label: '500 photos', price_id: null }];
    expect(selectAddonKeyForScope(addons, 'photos')).toBe('extra_photos_500');
  });
});
