<?php

namespace Modules\Evaluation\Service;

use GuzzleHttp\Psr7\Response;
use Modules\Evaluation\Repository\Import\ImportQuiz;

class ImportService
{
    private \PDO $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }
        
    /**
     * importGroupsOfRaters
     *
     * @param  string $mode
     * @param  int $modeId
     * @param  string $from
     * @param  string $theme
     * @param  array<mixed> $questions
     * @return void
     */
    public function importGroupsOfRaters(string $mode, $modeId, string $from, string $theme = '', $questions = [])
    {
        $importQuiz = new ImportQuiz($this->pdo);

        // si on importe depuis une liste de questions, on remplace le tableau des questions par une chaîne de caractères pour préparer la requête
        $questionsIds = '';
        if (\count($questions) > 0) {
            $questionsIds = " ( ";
            foreach ($questions as $question) {
                $questionsIds .= " $question, ";
            }
            $questionsIds = \rtrim($questionsIds, ', ') . ') ';
        }

        switch ($mode) {
            case 'campagne':
                switch ($from) {
                    case 'model':
                        $importQuiz->importGroupsFromModel($modeId, $theme);
                        break;
                    
                    case 'library':
                        $importQuiz->importGroupsFromLibrary($mode, $modeId, $theme);
                        break;
                    
                    default:
                        break;
                }
                break;

            case 'modele':
                $importQuiz->importGroupsFromLibrary($mode, $modeId, $theme);
                break;
        }
    }
}
