import { SidebarChatProvider } from '../sidebarProvider';

/**
 * Handles Project Chronicle messages: project CRUD, record listing/opening,
 * and the various chronicle-write entry points (planning, discussion, decision,
 * development, bug, retrospective).
 */
export async function handleChronicleMessage(provider: SidebarChatProvider, data: any): Promise<boolean> {
    switch (data.type) {
        case 'getChronicleProjects':
            await provider._sendChronicleProjects();
            return true;
        case 'createChronicleProject':
            await provider._createChronicleProject();
            return true;
        case 'setChronicleProject':
            await provider._setActiveChronicleProject(data.id);
            return true;
        case 'openChronicleFolder':
            await provider._openChronicleFolder();
            return true;
        case 'getChronicleRecords':
            await provider._sendChronicleRecords();
            return true;
        case 'openChronicleRecord':
            await provider._openChronicleRecord(data.path);
            return true;
        case 'writeChroniclePlanning':
            await provider._writeChroniclePlanningFromCurrentChat();
            return true;
        case 'writeChronicleDiscussion':
            await provider._writeChronicleDiscussionFromCurrentChat();
            return true;
        case 'writeChronicleDecision':
            await provider._writeChronicleDecisionFromInput();
            return true;
        case 'writeChronicleDevelopment':
            await provider._writeChronicleDevelopmentFromCurrentChat();
            return true;
        case 'writeChronicleBug':
            await provider._writeChronicleBugFromInput();
            return true;
        case 'writeChronicleRetrospective':
            await provider._writeChronicleRetrospectiveFromInput();
            return true;
        case 'writeChronicleRecord':
            await provider._writeChronicleRecord(data.recordType);
            return true;
        case 'setChronicleAutoRecord':
            // v2.2.70 — 자동 기록 On/Off 토글. 도구 드롭다운 메뉴에서 호출.
            await provider._setChronicleAutoRecord(!!data.enabled);
            return true;
        case 'getChronicleAutoRecord':
            await provider._sendChronicleAutoRecordStatus();
            return true;
        default:
            return false;
    }
}
