<?php

namespace Shm\ShmPayment\TBankPayment\TBankCollections;

use Shm\Collection\Collection;
use Shm\Shm;
use Shm\ShmTypes\StructureType;
use Shm\ShmUtils\MaterialIcons;

class TNominalBeneficiaries extends Collection
{


    public function schema(): StructureType
    {
        $schema = Shm::structure([

            "type" => Shm::enum([
                'IP_RESIDENT' => "ИП",
                'UL_RESIDENT' => "Юр.лицо",
            ])->required()->title("Тип")->inAdmin()->editable()->inTable(),

            'name' => Shm::string()->title("Наименование")->inAdmin()->editable()->inTable()->display(),

            "ipResident" => Shm::structure([
                "type" => Shm::static("IP_RESIDENT"),
                "firstName" => Shm::string()->title("Имя"),
                "middleName" => Shm::string()->title("Отчество"),
                "lastName" => Shm::string()->title("Фамилия"),
                "birthDate" => Shm::string()->title("Дата рождения в формате YYYY-MM-DD"),
                "birthPlace" => Shm::string()->title("Место рождения"),
                "citizenship" => Shm::string()->title("Гражданство"),
                "phoneNumber" => Shm::string()->title("Телефон"),
                "email" => Shm::string()->title("Email"),
                "passport" => Shm::structure([
                    "serial" => Shm::string()->title("Серия"),
                    "number" => Shm::string()->title("Номер"),
                    "date" => Shm::string()->title("Дата выдачи"),
                    "organization" => Shm::string()->title("Кем выдан"),
                    "divisionCode" => Shm::string()->title("Код подразделения"),
                ])->title("Паспорт")->inAdmin()->editable(),
                "registrationDate" => Shm::string()->title("Дата регистрации ИП в формате YYYY-MM-DD"),
                "registrationAddress" => Shm::string()->title("Адрес регистрации"),
                'inn' => Shm::string()->title("ИНН"),
                "snils" => Shm::string()->title("СНИЛС"),
            ])->cond(Shm::cond()->equals("type", "IP_RESIDENT"))->title("ИП")->inAdmin()->editable(),
            "ulResident" => Shm::structure([
                "type" => Shm::static("UL_RESIDENT"),
                "name" => Shm::string()->title("Наименование юридического лица"),
                "phoneNumber" => Shm::string()->title("Телефон"),
                "email" => Shm::string()->title("Email"),

                //LEGAL_ENTITY_ADDRESS
                "legalEntityAddress" => Shm::string()->title("Адрес юридического лица"),
                //POSTAL_ADDRESS
                "postalAddress" => Shm::string()->title("Почтовый адрес"),
                'registrationDate' => Shm::string()->title("Дата регистрации юридического лица в формате YYYY-MM-DD"),
                'opf' => Shm::enum([
                    "АО" => "Акционерное общество",
                    "ООО" => "Общество с ограниченной ответственностью",
                    "ПАО" => "Публичное акционерное общество",

                ])->title("Тип юридического лица"),
                "inn" => Shm::string()->title("ИНН"),
                "ogrn" => Shm::string()->title("ОГРН"),
            ])->cond(Shm::cond()->equals("type", "UL_RESIDENT"))->title("Юр.лицо")->inAdmin()->editable(),

            'bankDetails' => TNominalBankDetails::ID()->title("Банковские реквизиты")->inAdmin()->editable()->inTable()->display(),

            'scoring' => Shm::structure([
                "status" => Shm::enum([
                    'FAILED' => 'Отклонен',
                    'SUCCESS' => 'Одобрен',
                    'PENDING' => 'Ожидает проверки',
                ])->title("Статус проверки"),
                "warnings" => Shm::arrayOf(Shm::structure([
                    "code" => Shm::string()->title("Код предупреждения"),
                    "description" => Shm::string()->title("Описание предупреждения"),
                ]))->title("Предупреждения"),
                "errors" => Shm::arrayOf(Shm::structure([
                    "code" => Shm::string()->title("Код ошибки"),
                    "description" => Shm::string()->title("Описание ошибки"),
                ]))->title("Ошибки"),
            ])->title("Проверка в финансовом мониторинге")->inAdmin(),

        ])->inAdmin();

        $schema->icon(MaterialIcons::AccountBoxMultipleOutline());
        $schema->title("Юридические лица");
        $schema->canCreate()->canUpdate()->canDelete();


        return $schema;
    }
}
