<?php
namespace boru\ai\Conversation;

use boru\ai\Schema\Request;

class FullReplayStrategy implements ReplayStrategyInterface
{
    /** @var ConversationReplayService */
    protected $service;

    /** @var array */
    protected $options;

    public function __construct(ConversationReplayService $service = null, array $options = array())
    {
        $this->service = $service ? $service : new ConversationReplayService();
        $this->options = $options;
    }

    public function buildReplayMessages(Conversation $conversation, Request $currentRequest = null)
    {
        $messages = array();

        foreach ($conversation->turns() as $turn) {
            if (!$turn instanceof Turn) {
                continue;
            }

            foreach ($this->service->messagesFromTurn($turn, $this->options) as $message) {
                $messages[] = $message;
            }
        }

        return $messages;
    }
}
