<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\QAQuestionnaireSet;
use App\Models\QAQuestions;
use App\Classes\ValueObjects\Constants\QAType;

class QAQuestionsDemoSeeder extends Seeder
{
    public function run()
    {
        $questionnaireSets = [
            [
                'name' => 'Set 1',
                'description' => 'This is set 1 questions',
            ],
            [
                'name' => 'Set 2',
                'description' => 'Customer Service Satisfaction Questions',
            ],
            [
                'name' => 'Set 3',
                'description' => 'Survey Before conservation with BD ends',
            ],
            [
                'name' => 'Set 4',
                'description' => 'After First Order',
            ],
        ];

        foreach ($questionnaireSets as $set) {
            $questionnaireSet = QAQuestionnaireSet::create([
                'name' => $set['name'],
                'description' => $set['description'],
            ]);

            $questions = [];

            switch ($set['name']) {
                case 'Set 1':
                    $questions = [
                        [
                            'question_number' => 10,
                            'question_text' => 'Please select one',
                            'question_type' => QAType::MULTIPLE_CHOICES,
                            'is_start' => true,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 20,
                            'question_text' => 'Question text for question number 20?',
                            'question_type' => QAType::MULTIPLE_CHOICES,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 30,
                            'question_text' => 'Question text for question number 30?',
                            'question_type' => QAType::MULTIPLE_CHOICES,
                            'next_nested_question' => 300,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 40,
                            'question_text' => 'What is your name?',
                            'question_type' => QAType::FREE_TEXT,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 50,
                            'question_text' => 'The End',
                            'question_type' => QAType::ANSWER,
                            'is_start' => false,
                            'is_end' => true,
                        ],
                        [
                            'question_number' => 60,
                            'question_text' => 'We have received your request and will response as soon as possible.',
                            'question_type' => QAType::TICKET_CRM,
                            'is_start' => false,
                            'is_end' => true,
                        ],
                        [
                            'question_number' => 100,
                            'question_text' => 'Question text for question number 100?',
                            'question_type' => QAType::MULTIPLE_CHOICES,
                            'next_nested_question' => 110, //200 //3 digits - first level
                            'next_main_question' => 20,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 110,
                            'question_text' => 'Question text for question number 110?',
                            'question_type' => QAType::FREE_TEXT,
                            'next_nested_question' => 1000, //1000 //4 digits - second level
                            'next_main_question' => 20,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 300,
                            'question_text' => 'Question text for question number 300?',
                            'question_type' => QAType::MULTIPLE_CHOICES,
                            'next_main_question' => 40,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 600,
                            'question_text' => 'Shipping Fee Calculations',
                            'question_type' => QAType::ANSWER,
                            'is_start' => false,
                            'is_end' => true,
                        ],
                        [
                            'question_number' => 700,
                            'question_text' => 'Please enter your measurements',
                            'question_type' => QAType::FREE_TEXT,
                            'next_nested_question' => 710,
                            'next_main_question' => 20,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 710,
                            'question_text' => 'Please upload the photo proof',
                            'question_type' => QAType::DOCUMENT_UPLOAD,
                            'next_main_question' => 60,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 800,
                            'question_text' => 'What is your name?',
                            'question_type' => QAType::FREE_TEXT,
                            'next_nested_question' => 810,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 810,
                            'question_text' => 'Click Next to speak to our customer service',
                            'question_type' => QAType::FREE_TEXT,
                            'is_start' => false,
                            'is_end' => true,
                            'end_text' => 'We have received your request and will response as soon as possible.',
                        ],
                        [
                            'question_number' => 1000,
                            'question_text' => 'Question text for question number 1000?',
                            'question_type' => QAType::FREE_TEXT,
                            'next_nested_question' => 10000, //10000 - 5 digits - 3rd level
                            'next_main_question' => 20,
                            'is_start' => false,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 10000,
                            'question_text' => 'Question text for question number 10000?',
                            'question_type' => QAType::FREE_TEXT,
                            'next_main_question' => 20,
                            'is_start' => false,
                            'is_end' => false,
                        ],

                    ];
                    break;
                case 'Set 2':
                    $questions = [
                        [
                            'question_number' => 10,
                            'question_text' => 'How helpful is our agent towards resolving your issue?',
                            'question_type' => QAType::RATING_5_STARS,
                            'is_start' => true,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 20,
                            'question_text' => 'How would you rate our customer service experience?',
                            'question_type' => QAType::RATING_5_STARS,
                            'is_start' => false,
                            'is_end' => true,
                        ]
                    ];
                    break;
                case 'Set 3':
                    $questions = [
                        [
                            'question_number' => 10,
                            'question_text' => 'Is our service suite for you?',
                            'question_type' => QAType::MULTIPLE_CHOICES,
                            'is_start' => true,
                            'is_end' => false,
                        ],
                        [
                            'question_number' => 20,
                            'question_text' => 'Can you rate our sales agent performance whether you comfortable when chatting with them',
                            'question_type' => QAType::RATING_5_STARS,
                            'is_start' => false,
                            'is_end' => true,
                        ]
                    ];
                    break;
                case 'Set 4':
                    $questions = [
                        [
                            'question_number' => 10,
                            'question_text' => 'How satisfy you are after your first order?',
                            'question_type' => QAType::RATING_5_STARS,
                            'is_start' => true,
                            'is_end' => false,
                        ]
                    ];
                    break;
            }

            foreach ($questions as $key => $questionData) {
                $question = new QAQuestions;
                $question->question_number = $questionData['question_number'];
                $question->question_text = $questionData['question_text'];
                $question->question_type = $questionData['question_type'];
                $question->questionnaire_set_id = $questionnaireSet->id;

                if (isset($questionData['next_nested_question'])) {
                    $question->next_nested_question = $questionData['next_nested_question'];
                }
                if (isset($questionData['next_main_question'])) {
                    $question->next_main_question = $questionData['next_main_question'];
                }

                $question->is_start = $questionData['is_start'];
                $question->is_end = $questionData['is_end'];
                if (isset($questionData['end_text'])) {
                    $question->end_text = $questionData['end_text'];
                }

                $question->order = $key + 1;
                $question->save();
            }
        }
    }
}
