import { describe, it, expect, vi, beforeEach } from 'vitest';
import { batchGenerateContentBriefs } from '../../seo/issue-batch-briefs.js';
const generateContentBriefMock = vi.fn();
const generateContentResearchMock = vi.fn();
const contentBriefFromMetadataMock = vi.fn();
vi.mock('../../seo/issue-content-brief.js', () => ({
    supportsContentBrief: (type) => ['thin-content', 'missing-h1'].includes(type),
    generateContentBrief: (...args) => generateContentBriefMock(...args),
    contentBriefFromMetadata: (...args) => contentBriefFromMetadataMock(...args),
    contentBriefToMetadata: (brief) => ({ contentBrief: brief }),
}));
vi.mock('../../seo/issue-content-research.js', () => ({
    supportsContentResearch: (type) => type === 'thin-content',
    generateContentResearch: (...args) => generateContentResearchMock(...args),
    contentResearchFromMetadata: () => null,
    contentResearchToMetadata: (research) => ({ contentResearch: research }),
}));
describe('batchGenerateContentBriefs', () => {
    beforeEach(() => {
        generateContentBriefMock.mockReset();
        generateContentResearchMock.mockReset();
        contentBriefFromMetadataMock.mockReset();
        contentBriefFromMetadataMock.mockReturnValue(null);
    });
    it('skips issues with fresh cached briefs', async () => {
        contentBriefFromMetadataMock.mockReturnValueOnce({ summary: 'cached' });
        generateContentBriefMock.mockResolvedValue({
            ok: true,
            brief: { summary: 'new brief', fingerprint: 'f', generatedAt: 'now' },
        });
        const update = vi.fn(async () => ({}));
        const deps = { db: { seoIssue: { update } }, userId: 'u1', collection: 'pages' };
        const result = await batchGenerateContentBriefs([
            { id: 'i1', type: 'thin-content', title: 'Thin', entityId: 'p1' },
            { id: 'i2', type: 'missing-h1', title: 'H1', entityId: 'p2' },
        ], new Map([
            ['p1', { collection: 'pages', updatedAt: new Date(), entity: { entityId: 'p1' } }],
            ['p2', { collection: 'pages', updatedAt: new Date(), entity: { entityId: 'p2' } }],
        ]), deps, { skipExisting: true });
        expect(result.skipped).toBe(1);
        expect(result.generated).toBe(1);
        expect(generateContentBriefMock).toHaveBeenCalledTimes(1);
        expect(update).toHaveBeenCalledTimes(1);
    });
    it('runs research before brief when includeResearch is true', async () => {
        generateContentResearchMock.mockResolvedValue({
            ok: true,
            research: { summary: 'research', fingerprint: 'x', generatedAt: 'now' },
        });
        generateContentBriefMock.mockResolvedValue({
            ok: true,
            brief: { summary: 'brief', fingerprint: 'y', generatedAt: 'now' },
        });
        const update = vi.fn(async () => ({}));
        const deps = { db: { seoIssue: { update } }, userId: 'u1', collection: 'pages' };
        await batchGenerateContentBriefs([{ id: 'i1', type: 'thin-content', title: 'Thin', entityId: 'p1' }], new Map([
            ['p1', { collection: 'pages', updatedAt: new Date(), entity: { entityId: 'p1' } }],
        ]), deps, { skipExisting: false, includeResearch: true });
        expect(generateContentResearchMock).toHaveBeenCalledTimes(1);
        expect(generateContentBriefMock).toHaveBeenCalledTimes(1);
        expect(update).toHaveBeenCalledTimes(1);
    });
});
//# sourceMappingURL=issue-batch-briefs.test.js.map