import { test, expect } from '@playwright/test';

test.describe('Ghostwriter Persistence', () => {
    test('Scenario 2.4.2 (P0): Session Saved as Completed', async ({ request }) => {
        // GIVEN: A chat session flow is completed
        // This is an API/Integration test, so we hit the endpoint directly if possible, 
        // OR we use the service capability if we were in a unit test. 
        // For Playwright Integration (API), we assume an endpoint exists to finalize.

        // Setup: Create a session
        const createRes = await request.post('/api/sessions', { data: { title: 'Test Session' } });
        const { sessionId } = await createRes.json();

        // WHEN: User saves the final draft
        const saveRes = await request.post(`/api/sessions/${sessionId}/finalize`, {
            data: { finalContent: 'My Lesson' }
        });
        expect(saveRes.status()).toBe(200);

        // THEN: Session status is COMPLETED
        const getRes = await request.get(`/api/sessions/${sessionId}`);
        const session = await getRes.json();

        expect(session.status).toBe('COMPLETED');
        expect(session.finalArtifact).toBe('My Lesson');
    });
});
