<?php

namespace lucidpen;

use core\SingletonTrait;

if (!defined('ABSPATH'))
    exit;

/**
 * class Reporter
 * This class extends the Assistant class to provide specific functionality for interviewing users
 * and drafting blog posts based on their responses.
 */
class Reporter extends AssistantTemplate
{
    protected const ASSISTANT_PANEL_TITLE = '🎤 AI Interviewer';
    protected const EDITOR_PANEL_TITLE = '📝 Draft Your Blog';
    protected const CATEGORY = 'Blog';
    protected const SLUG = 'blogs';
    protected const SLUG_OPTION_NAME = LCPN_OPT_SLUG_BLOG;
    protected const SYSTEM_MESSAGE_CHAT = 'You are an interviewer helping a user prepare a blog post. Your job is to ask thoughtful, open-ended questions to deeply understand the user’s ideas, intentions, and the context of their blog. In each conversation, ask guiding questions to help the author clarify their thoughts, expand on their experiences, and enrich the content of the future blog post. Focus on exploring the user’s goals, message, intended audience, and desired tone. Do not write or summarize the blog until the user explicitly asks you to draft a version. Continue the interview, offering suggestions and guidance, until the user requests a blog draft.';

    protected const SYSTEM_MESSAGE_DRAFT = 'You are an interviewer helping a user prepare a blog post. Ask guiding questions to help the user clarify their thoughts and context. When explicitly asked, draft a complete blog post in markdown based on everything learned so far.';

    protected const SYSTEM_MESSAGE_TITLE = 'You are a helpful assistant that writes concise titles.';

    public function chat($response, $history=[])
    {
        return $this->ask($response, $history, self::SYSTEM_MESSAGE_CHAT);
    }

    public function draft($history, $content=null)
    {

        $question = empty($context) ?
            'Now, please draft a complete blog post in markdown.' :
            "Please update the following content with the most recent details from our chat history. Here is the current content:\n\n{$context}\n\n";

        return $this->ask($question, $history, self::SYSTEM_MESSAGE_DRAFT);
    }

    public function title($draft)
    {
        return $this->ask('Suggest a short, clear, and relevant title (max 8 words) for the following content: ' . $draft, [], self::SYSTEM_MESSAGE_TITLE);
    }

}

// Register the Reporter class
Reporter::register(true);
