<?php

namespace Database\Seeders\Objects;

use App\Models\Dictionaries\DictionaryItem;
use App\Models\Objects\Field;
use App\Models\Objects\FieldType;
use App\Models\Objects\ObjectType;
use App\Transformers\Dictionaries\DictionaryItemTransformer;
use App\Transformers\Objects\ObjectTypeTransformer;
use Illuminate\Database\Seeder;

class FieldsTableSeeder extends Seeder {
    public array $fields = [
        'header' => [
            'title' => 'Текст заголовка',
            'type' => FieldType::TEXT
        ],
        'header-type' => [
            'title' => 'Тип заголовка',
            'type' => FieldType::RELATION,
            'required' => true,
            'params' => [
                'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
                'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'title-types']]]
            ]
        ],
        'header-required' => [
            'title' => 'Текст заголовка',
            'type' => FieldType::TEXT,
            'required' => true
        ],

        'documents' => [
            'title' => 'Документы',
            'type' => FieldType::DOCUMENT,
            'multiple' => true
        ],
        'documents-required' => [
            'title' => 'Документы',
            'type' => FieldType::DOCUMENT,
            'multiple' => true,
            'required' => true
        ],

        'html' => [
            'title' => 'Содержимое текстового блока',
            'type' => FieldType::HTML
        ],
        'html-required' => [
            'title' => 'Содержимое текстового блока',
            'type' => FieldType::HTML,
            'required' => true
        ],

//        'list-type' => [
//            'title' => 'Вид списка',
//            'type' => FieldType::RELATION,
//            'required' => true,
//            'params' => [
//                'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
//                'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'list-types']]]
//            ]
//        ],
//        'list-items' => [
//            'title' => 'Элементы списка',
//            'type' => FieldType::TEXT,
//            'multiple' => true,
//            'required' => true
//        ],

        'images' => [
            'title' => 'Изображения',
            'type' => FieldType::IMAGE,
            'multiple' => true
        ],
        'images-required' => [
            'title' => 'Изображения',
            'type' => FieldType::IMAGE,
            'multiple' => true,
            'required' => true
        ],

        'video-url' => [
            'title' => 'Ссылка на видео',
            'type' => FieldType::STRING,
            'required' => true
        ],

        'button-title' => [
            'title' => 'Текст',
            'type' => FieldType::STRING,
            'required' => true
        ],
        'button-url' => [
            'title' => 'Ссылка на кнопку',
            'type' => FieldType::STRING,
            'required' => true
        ],

        'iframe-url' => [
            'title' => 'Ссылка',
            'type' => FieldType::STRING,
            'required' => true
        ],

        'contact-name' => [
            'title' => 'Наименование',
            'type' => FieldType::STRING,
        ],
        'contact-legal-address' => [
            'title' => 'Юридический адрес',
            'type' => FieldType::STRING,
        ],
        'contact-location-address' => [
            'title' => 'Фактический адрес',
            'type' => FieldType::STRING,
        ],
        'contact-email' => [
            'title' => 'Email',
            'type' => FieldType::STRING,
        ],
        'contact-phone' => [
            'title' => 'Телефон',
            'type' => FieldType::STRING,
        ],
        'contact-description' => [
            'title' => 'Информация',
            'type' => FieldType::HTML,
        ],

        'feedback-support-email' => [
            'title' => 'Email кому будет отправлен ответ',
            'type' => FieldType::STRING,
            'required' => true,
        ],
        'feedback-form-type' => [
            'title' => 'Тип формы',
            'type' => FieldType::RELATION,
            'required' => true,
            'params' => [
                'related' => ObjectType::class, 'transformer' => ObjectTypeTransformer::class,
                'options' => ['show' => true, 'whereHas' => ['parent' => ['name' => 'feedback-form']]]
            ]
        ],

        'feedback-email' => [
            'title' => 'Электронная почта',
            'type' => FieldType::STRING,
            'required' => true,
        ],
        'feedback-name' => [
            'title' => 'Ваше имя',
            'type' => FieldType::STRING,
            'required' => true,
        ],
        'feedback-type' => [
            'title' => 'Тема обращения',
            'type' => FieldType::RELATION,
            'required' => true,
            'params' => [
                'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
                'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'feedback-types']]],
            ]
        ],
        'feedback-message' => [
            'title' => 'Текст сообщения',
            'type' => FieldType::TEXT,
            'required' => true,
        ],

        'operation-type' => [
            'title' => 'Вид работы',
            'type' => FieldType::RELATION,
            'required' => true,
            'params' => [
                'appearance' => 'radio',
                'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
                'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'operation-types']]]
            ]
        ],
        'order-name' => [
            'title' => 'Наименование приказа',
            'type' => FieldType::STRING,
            'required' => true
        ],
        'order-date' => [
            'title' => 'Дата приказа',
            'type' => FieldType::DATE,
            'required' => true
        ],
        'order-document' => [
            'title' => 'Документ приказа',
            'type' => FieldType::DOCUMENT,
            'required' => true
        ],

        'listings' => [
            'title' => 'Вхождение в перечень ПП',
            'type' => FieldType::RELATION,
            'multiple' => true,
            'params' => [
                'appearance' => 'checkbox',
                'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
                'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'listings']]]
            ]
        ],

        'active-since' => [
            'title' => 'Дата начала действия',
            'type' => FieldType::DATE,
            'required' => true
        ],
        'active-till' => [
            'title' => 'Дата окончания действия',
            'type' => FieldType::DATE
        ],

        'developer' => [
            'title' => 'Разработчик',
            'type' => FieldType::STRING
        ]
    ];

    public function run() {
        collect($this->fields)->each(function($data, $name) {
            $field = Field::firstOrCreate(['name' => $name]);
            $field->update($data);
        });
    }
}
