<?php

use Illuminate\Support\Arr;
use App\Services\FilterService;
use App\Services\FilterItemService;
use Illuminate\Database\Seeder;

class FilterSeeder extends Seeder
{

    private $filterService;

    public function __construct(
        FilterService $filterService,
        FilterItemService $filterItemService
    ) {
        $this->filterService = $filterService;
        $this->filterItemService = $filterItemService;
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $filters = [
            [
                'title' => 'category',
                'items' => [
                    'Ambulantisering', 'Forensisch', 'Geneesmiddelen en somatiek', 'Herstel', 'Methodieken', 'Professioneel handelen', 'Professionele attitude', 'Psychopathologie', 'Suïcidepreventie', 'Voorbehouden handelingen', 'Wetgeving'
                ]
            ],
            [
                'title' => 'audience',
                'items' => [
                    'Aandachtsfunctionarissen', 'Agogen', 'Ambulant begeleider', 'Artsen', 'Behandelaren', 'Cognitief gedragstherapeuten', 'Cognitief gedragstherapeutisch werkers', 'ervaringsdeskundigen', 'ervaringswerkers',
                    'gezondheidstherapeuten', 'groepsbegeleiders', 'groepswerkers', 'GZ psychologen', 'jongerenwerkers', 'klinisch psychologen', 'leerling verpleegkundigen', 'maatschappelijk werkers', 'orthopedagogen',
                    'pedagogen', 'persoonlijk begeleiders', 'physician assistants', 'POH GGZ', 'psychiaters', 'psychologen', 'psychotherapeuten', 'schuldhulpverleners', 'sociaal pedagogisch hulpverleners', 'sociaal psychiatrisch verpleegkundigen',
                    'social worker', 'sociotherapeuten', 'trainers', 'vaktherapeuten', 'verpleegkundig specialisten', 'verpleegkundigen', 'verzorgenden', 'woonbegeleiders', 'zorg behandel inrichtingswerkers'
                ]
            ],
            [
                'title' => 'format_version',
                'items' => [
                    'option-A',
                    'option-B',
                ]
            ],
            [
                'title' => 'course',
                'items' => [
                    'Forensische leerlijn', 'LVB', 'Zichtbaar vakmanschap'
                ]
            ],
            [
                'title' => 'level',
                'items' => [
                    'MBO', 'MBO 3/4', 'MBO 4', 'HBO', 'HBO+Master', 'WO', 'NLQF 6'
                ]
            ],
            [
                'title' => 'developers'
            ],
            [
                'title' =>
                'dev_environment',
                'items' => [
                    'aNS'
                ]
            ],
            [
                'title' => 'product_type',
                'items' => [
                    'Leertraject'
                ]
            ],
            [
                'title' => 'made_by',
                'items' => [
                    'Danaë'
                ]
            ],
            [
                'title' => 'register',
                'items' => [
                    'ABAN', 'Accreditatiebureau Cluster 123', 'FGZpT', 'In aanvraag', 'Kwaliteitsregister POH-GGZ', 'Kwaliteitsregister Psychotherapie NVP', 'Kwaliteitsregister V&V', 'NIP A&O | NIP A&G', 'NIP Eerstelijnspsychologen', '	NIP Kinder- en Jeugdpsycholoog (K&J) / NVO Orthopedagoog-Generalist (OG)', 'NIP-Lichaamsgericht Werkend Psycholoog', 'NIP-Neurofeedbackpsycholoog', 'NIP-Psycholoog Mediator', 'nvt', 'NVvp', 'Register Vaktherapie', 'Registerplein', 'SKJ', 'Verpleegkundig Specialisten Register', 'VVGN'
                ]
            ],
            [
                'title' => 'status',
                'items' => [
                    ['title' => 'Geprioriteerd', 'color' => '#19DB7A'],
                    ['title' => 'In ontwikkeling', 'color' => '#F5AB00'],
                    ['title' => 'Opgeleverd', 'color' => '#31B8CE'],
                    ['title' => 'Test', 'color' => '#FFFF7E'],
                    ['title' => 'Vervallen - actief', 'color' => '#6F7782'],
                    ['title' => 'Vervallen - niet-actief', 'color' => '#000000'],
                ]
            ],
            [
                'title' => 'theme',
                'items' => [
                    'Ambulantisering', 'Eigen regie', 'Medicatie bij psychiatrische aandoeningen', 'Meldcode Kindermishandeling en Kindcheck', 'Psychopathologie', 'Suïcidepreventie'
                ]
            ],
            [
                'title' => 'type',
                'items' => [
                    [
                        'title' => 'GGZ-instellingen',
                        //  'subtitle' => 'type A,B,C'
                    ],
                    [
                        'title' => 'Scholen',
                        // 'subtitle' => 'type D'
                    ],
                    [
                        'title' => 'vLOGO onderwijs',
                        // 'subtitle' => 'type E'
                    ],
                    'Gratis'
                ]
            ],
            [
                'title' => 'quality_standards',
                'items' => [
                    'option_1',
                    'option_2',
                    'option_3',
                ]
            ],
        ];

        foreach ($filters as $filter) {

            $new_filter = $this->filterService->save(Arr::except($filter, ['items']));

            if (isset($filter['items'])) {

                foreach ($filter['items'] as $item) {

                    $data = [];

                    if (is_string($item)) {
                        $data = [
                            'title' => $item,
                            'filter_id' => $new_filter->id
                        ];
                    } elseif (Arr::isAssoc($item)) {
                        foreach ($item as $key => $value) {
                            $data[$key] = $value;
                        }
                        $data['filter_id'] = $new_filter->id;
                    }

                    $new_filter_item = $this->filterItemService->save($data);
                }
            }
        }
    }
}
