import { describe, it, expect } from 'vitest';
import { generateTypes } from '../../codegen/index.js';
function createMinimalConfig(overrides = {}) {
    return {
        platform: {
            database: {},
            storage: {},
        },
        auth: {
            providers: [],
        },
        collections: {},
        ...overrides,
    };
}
describe('generateTypes', () => {
    it('produces output containing collection interface names', () => {
        const config = createMinimalConfig({
            collections: {
                posts: {
                    slug: 'posts',
                    labels: { singular: 'Post', plural: 'Posts' },
                    fields: {
                        title: { type: 'text', label: 'Title', required: true },
                    },
                },
                pages: {
                    slug: 'pages',
                    labels: { singular: 'Page', plural: 'Pages' },
                    fields: {
                        heading: { type: 'text', label: 'Heading', required: true },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toContain('export interface PostsDocument');
        expect(output).toContain('export interface PagesDocument');
        expect(output).toContain('ActuateCollections');
    });
    it('handles text, number, boolean field types', () => {
        const config = createMinimalConfig({
            collections: {
                items: {
                    slug: 'items',
                    labels: { singular: 'Item', plural: 'Items' },
                    fields: {
                        name: { type: 'text', label: 'Name', required: true },
                        count: { type: 'number', label: 'Count', required: true },
                        active: { type: 'boolean', label: 'Active', required: true },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toContain('name: string;');
        expect(output).toContain('count: number;');
        expect(output).toContain('active: boolean;');
    });
    it('handles select fields with options (generates union types)', () => {
        const config = createMinimalConfig({
            collections: {
                articles: {
                    slug: 'articles',
                    labels: { singular: 'Article', plural: 'Articles' },
                    fields: {
                        status: {
                            type: 'select',
                            label: 'Status',
                            required: true,
                            options: [
                                { label: 'Draft', value: 'draft' },
                                { label: 'Published', value: 'published' },
                                { label: 'Archived', value: 'archived' },
                            ],
                        },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toContain('"draft"');
        expect(output).toContain('"published"');
        expect(output).toContain('"archived"');
        expect(output).toMatch(/"draft" \| "published" \| "archived"/);
    });
    it('handles optional fields (adds ?)', () => {
        const config = createMinimalConfig({
            collections: {
                posts: {
                    slug: 'posts',
                    labels: { singular: 'Post', plural: 'Posts' },
                    fields: {
                        title: { type: 'text', label: 'Title', required: true },
                        subtitle: { type: 'text', label: 'Subtitle' },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toMatch(/title: string;/);
        expect(output).toMatch(/subtitle\?: string;/);
    });
    it('handles globals', () => {
        const config = createMinimalConfig({
            collections: {
                posts: {
                    slug: 'posts',
                    labels: { singular: 'Post', plural: 'Posts' },
                    fields: {
                        title: { type: 'text', label: 'Title', required: true },
                    },
                },
            },
            globals: {
                settings: {
                    slug: 'settings',
                    label: 'Site Settings',
                    fields: {
                        siteName: { type: 'text', label: 'Site Name', required: true },
                        maintenance: { type: 'boolean', label: 'Maintenance Mode' },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toContain('export interface SettingsGlobal');
        expect(output).toContain('ActuateGlobals');
        expect(output).toContain('ActuateGlobalSlug');
        expect(output).toContain('siteName: string;');
        expect(output).toMatch(/maintenance\?: boolean;/);
    });
    it('generates CreateInput and UpdateInput types for collections', () => {
        const config = createMinimalConfig({
            collections: {
                posts: {
                    slug: 'posts',
                    labels: { singular: 'Post', plural: 'Posts' },
                    fields: {
                        title: { type: 'text', label: 'Title', required: true },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toContain('PostsDocumentCreateInput');
        expect(output).toContain('PostsDocumentUpdateInput');
    });
    it('generates ActuateClient interface', () => {
        const config = createMinimalConfig({
            collections: {
                posts: {
                    slug: 'posts',
                    labels: { singular: 'Post', plural: 'Posts' },
                    fields: {
                        title: { type: 'text', label: 'Title', required: true },
                    },
                },
            },
        });
        const output = generateTypes(config);
        expect(output).toContain('export interface ActuateClient');
        expect(output).toContain('find<K extends keyof ActuateCollections>');
        expect(output).toContain('findOne<K extends keyof ActuateCollections>');
    });
    it('includes auto-generated header comment', () => {
        const config = createMinimalConfig();
        const output = generateTypes(config);
        expect(output).toContain('Auto-generated by @actuate-media/cms-core');
        expect(output).toContain('DO NOT EDIT');
    });
});
//# sourceMappingURL=generate-types.test.js.map