import { describe, it, expect } from 'vitest';
import { blogPostCollection, caseStudyCollection, portfolioCollection, serviceCollection, locationCollection, teamMemberCollection, faqCollection, testimonialCollection, getTemplatesForCollection, } from '../../collections/presets.js';
import { BUILT_IN_TEMPLATES } from '../../page-builder/templates.js';
describe('collection presets', () => {
    it('blogPostCollection sets BlogPosting schema and archive path', () => {
        const c = blogPostCollection();
        expect(c.slug).toBe('posts');
        expect(c.type).toBe('post');
        expect(c.urlPrefix).toBe('blog');
        expect(c.seo?.defaultSchemaType).toBe('BlogPosting');
        expect(c.seo?.archivePath).toBe('/blog');
        expect(c.fields.title).toBeDefined();
        expect(c.fields.slug).toBeDefined();
        expect(c.fields.body).toBeDefined();
        expect(c.fields.metaTitle).toBeDefined();
    });
    it('caseStudyCollection has challenge/solution/results + metrics', () => {
        const c = caseStudyCollection();
        expect(c.seo?.defaultSchemaType).toBe('Article');
        expect(c.fields.challenge).toBeDefined();
        expect(c.fields.solution).toBeDefined();
        expect(c.fields.results).toBeDefined();
        expect(c.fields.keyMetrics).toBeDefined();
        expect(c.fields.clientName?.required).toBe(true);
    });
    it('portfolioCollection has a gallery + project URL', () => {
        const c = portfolioCollection();
        expect(c.seo?.defaultSchemaType).toBe('CreativeWork');
        expect(c.fields.gallery?.type).toBe('array');
        expect(c.fields.projectUrl?.type).toBe('url');
    });
    it('serviceCollection is a page-type collection with Service schema', () => {
        const c = serviceCollection();
        expect(c.type).toBe('page');
        expect(c.seo?.defaultSchemaType).toBe('Service');
        expect(c.fields.benefits?.type).toBe('array');
        expect(c.fields.price?.type).toBe('number');
    });
    it('locationCollection sets LocalBusiness schema with address/geo', () => {
        const c = locationCollection();
        expect(c.seo?.defaultSchemaType).toBe('LocalBusiness');
        expect(c.fields.address).toBeDefined();
        expect(c.fields.latitude).toBeDefined();
        expect(c.fields.longitude).toBeDefined();
        expect(c.fields.servicesOffered?.type).toBe('relationship');
    });
    it('teamMemberCollection has Person schema, role, social links', () => {
        const c = teamMemberCollection();
        expect(c.seo?.defaultSchemaType).toBe('Person');
        expect(c.fields.role?.required).toBe(true);
        expect(c.fields.socialLinks?.type).toBe('array');
    });
    it('faqCollection excludes from sitemap (fragments)', () => {
        const c = faqCollection();
        expect(c.seo?.defaultSchemaType).toBe('FAQPage');
        expect(c.seo?.excludeFromSitemap).toBe(true);
        expect(c.fields.question?.required).toBe(true);
        expect(c.fields.answer?.required).toBe(true);
    });
    it('testimonialCollection is Review schema, has rating 1-5', () => {
        const c = testimonialCollection();
        expect(c.seo?.defaultSchemaType).toBe('Review');
        expect(c.fields.rating.min).toBe(1);
        expect(c.fields.rating.max).toBe(5);
    });
    it('overrides merge cleanly: extraFields are added without losing presets', () => {
        const c = blogPostCollection({
            extraFields: {
                category: { type: 'text', label: 'Category' },
            },
        });
        expect(c.fields.title).toBeDefined();
        expect(c.fields.body).toBeDefined();
        expect(c.fields.category?.label).toBe('Category');
    });
    it('overrides can replace fields entirely', () => {
        const c = blogPostCollection({
            fields: { customTitle: { type: 'text', label: 'Custom title' } },
        });
        // When `fields` is passed (not `extraFields`), it merges on top of defaults
        // — the call site retains the defaults plus their own custom field.
        expect(c.fields.customTitle?.label).toBe('Custom title');
        expect(c.fields.title).toBeDefined();
    });
    it('overrides can change slug and urlPrefix', () => {
        const c = blogPostCollection({ slug: 'news', urlPrefix: 'news' });
        expect(c.slug).toBe('news');
        expect(c.urlPrefix).toBe('news');
    });
    it('seo overrides merge with preset seo block', () => {
        const c = blogPostCollection({ seo: { sitemapPriority: 0.9 } });
        expect(c.seo?.defaultSchemaType).toBe('BlogPosting');
        expect(c.seo?.sitemapPriority).toBe(0.9);
        expect(c.seo?.archivePath).toBe('/blog');
    });
});
describe('getTemplatesForCollection', () => {
    it('maps known content collections to their primary template', () => {
        expect(getTemplatesForCollection('posts').primary).toBe('blog-post');
        expect(getTemplatesForCollection('case-studies').primary).toBe('case-study');
        expect(getTemplatesForCollection('portfolio').primary).toBe('portfolio');
        expect(getTemplatesForCollection('services').primary).toBe('service');
        expect(getTemplatesForCollection('locations').primary).toBe('location');
        expect(getTemplatesForCollection('team').primary).toBe('team-member');
    });
    it('returns alternates for ambiguous types', () => {
        const portfolio = getTemplatesForCollection('portfolio');
        expect(portfolio.alternates.length).toBeGreaterThan(0);
        const pages = getTemplatesForCollection('pages');
        expect(pages.primary).toBe('blank');
        expect(pages.alternates).toContain('landing');
    });
    it('soft-matches via includes (e.g. blog-news → blog-post)', () => {
        expect(getTemplatesForCollection('blog-news').primary).toBe('blog-post');
    });
    it('returns null primary for unknown collections', () => {
        expect(getTemplatesForCollection('completely-unknown-xyz').primary).toBe(null);
    });
    it('all suggested template IDs exist in BUILT_IN_TEMPLATES', () => {
        const seen = new Set();
        for (const slug of [
            'posts',
            'case-studies',
            'portfolio',
            'services',
            'locations',
            'team',
            'pages',
        ]) {
            const { primary, alternates } = getTemplatesForCollection(slug);
            if (primary)
                seen.add(primary);
            for (const a of alternates)
                seen.add(a);
        }
        for (const id of seen) {
            expect(BUILT_IN_TEMPLATES[id]).toBeDefined();
        }
    });
});
//# sourceMappingURL=presets.test.js.map