<commit_before><?php
namespace SPHERE\Application\People\Meta\Student;

use SPHERE\Application\Corporation\Company\Company;
use SPHERE\Application\Corporation\Company\Service\Entity\TblCompany;
use SPHERE\Application\Education\Lesson\Division\Division;
use SPHERE\Application\Education\Lesson\Division\Service\Entity\TblDivision;
use SPHERE\Application\Education\Lesson\Division\Service\Entity\TblLevel;
use SPHERE\Application\Education\Lesson\Subject\Service\Entity\TblSubject;
use SPHERE\Application\Education\Lesson\Subject\Subject;
use SPHERE\Application\Education\Lesson\Term\Service\Entity\TblYear;
use SPHERE\Application\Education\Lesson\Term\Term;
use SPHERE\Application\Education\School\Course\Course;
use SPHERE\Application\Education\School\Type\Type;
use SPHERE\Application\People\Group\Group;
use SPHERE\Application\People\Meta\Student\Service\Data;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudent;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentAgreementType;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentBaptism;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentBilling;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentIntegration;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentLocker;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentMedicalRecord;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentSubject;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentSubjectRanking;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentSubjectType;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentTransport;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudent;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentAgreement;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentBaptism;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentDisorder;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentFocus;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentIntegration;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentLocker;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentMedicalRecord;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentTransfer;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentTransport;
use SPHERE\Application\People\Meta\Student\Service\Service\Integration;
use SPHERE\Application\People\Meta\Student\Service\Setup;
use SPHERE\Application\People\Person\Person;
use SPHERE\Application\People\Person\Service\Entity\TblPerson;
use SPHERE\Application\People\Relationship\Relationship;
use SPHERE\Application\People\Relationship\Service\Entity\TblSiblingRank;
use SPHERE\Application\Setting\Consumer\Consumer;
use SPHERE\Common\Frontend\Form\IFormInterface;
use SPHERE\Common\Frontend\Message\Repository\Success;
use SPHERE\Common\Window\Redirect;

/**
 * Class Service
 *
 * @package SPHERE\Application\People\Meta\Student
 */
class Service extends Integration
{

    /**
     * @return false|ViewStudent[]
     */
    public function viewPerson()
    {

        return ( new Data($this->getBinding()) )->viewStudent();
    }

    /**
     * @return false|ViewStudentAgreement[]
     */
    public function viewStudentAgreement()
    {

        return ( new Data($this->getBinding()) )->viewStudentAgreement();
    }

    /**
     * @return false|ViewStudentBaptism[]
     */
    public function viewStudentBaptism()
    {

        return ( new Data($this->getBinding()) )->viewStudentBaptism();
    }

//    /**
//     * @return false|ViewStudentBilling[]
//     */
//    public function viewStudentBilling()
//    {
//
//        return (new Data($this->getBinding()))->viewStudentBilling();
//    }

    /**
     * @return false|ViewStudentDisorder[]
     */
    public function viewStudentDisorder()
    {

        return ( new Data($this->getBinding()) )->viewStudentDisorder();
    }

    /**
     * @return false|ViewStudentFocus[]
     */
    public function viewStudentFocus()
    {

        return ( new Data($this->getBinding()) )->viewStudentFocus();
    }

    /**
     * @return false|ViewStudentIntegration[]
     */
    public function viewStudentIntegration()
    {

        return ( new Data($this->getBinding()) )->viewStudentIntegration();
    }

    /**
     * @return false|ViewStudentIntegration[]
     */
    public function viewStudentLiberation()
    {

        return ( new Data($this->getBinding()) )->viewStudentLiberation();
    }

    /**
     * @return false|ViewStudentLocker[]
     */
    public function viewStudentLocker()
    {

        return ( new Data($this->getBinding()) )->viewStudentLocker();
    }

    /**
     * @return false|ViewStudentMedicalRecord[]
     */
    public function viewStudentMedicalRecord()
    {

        return ( new Data($this->getBinding()) )->viewStudentMedicalRecord();
    }

//    /**
//     * @return false|ViewStudentSubject[]
//     */
//    public function viewStudentSubject()
//    {
//
//        return ( new Data($this->getBinding()) )->viewStudentSubject();
//    }

    /**
     * @return false|ViewStudentTransfer[]
     */
    public function viewStudentTransfer()
    {

        return ( new Data($this->getBinding()) )->viewStudentTransfer();
    }

    /**
     * @return false|ViewStudentTransport[]
     */
    public function viewStudentTransport()
    {

        return ( new Data($this->getBinding()) )->viewStudentTransport();
    }

    /**
     * @param bool $doSimulation
     * @param bool $withData
     *
     * @return string
     */
    public function setupService($doSimulation, $withData)
    {

        $Protocol = (new Setup($this->getStructure()))->setupDatabaseSchema($doSimulation);
        if (!$doSimulation && $withData) {
            (new Data($this->getBinding()))->setupDatabaseContent();
        }
        return $Protocol;
    }

    /**
     * @param $LockerNumber
     * @param $LockerLocation
     * @param $KeyNumber
     *
     * @return TblStudentLocker
     */
    public function insertStudentLocker(
        $LockerNumber,
        $LockerLocation,
        $KeyNumber
    ) {

        return (new Data($this->getBinding()))->createStudentLocker(
            $LockerNumber,
            $LockerLocation,
            $KeyNumber
        );
    }

    /**
     * @param TblSiblingRank $tblSiblingRank
     *
     * @return TblStudentBilling
     */
    public function insertStudentBilling(TblSiblingRank $tblSiblingRank)
    {

        return (new Data($this->getBinding()))->createStudentBilling(
            $tblSiblingRank
        );
    }

    /**
     * @param                $Disease
     * @param                $Medication
     * @param                $Insurance
     * @param int|null       $InsuranceState
     * @param TblPerson|null $tblPersonAttendingDoctor
     *
     * @return TblStudentMedicalRecord
     */
    public function insertStudentMedicalRecord(
        $Disease,
        $Medication,
        $Insurance,
        $InsuranceState = 0,
        TblPerson $tblPersonAttendingDoctor = null
    ) {

        return (new Data($this->getBinding()))->createStudentMedicalRecord(
            $Disease,
            $Medication,
            $tblPersonAttendingDoctor,
            $InsuranceState,
            $Insurance
        );
    }

    /**
     * @param TblStudent              $tblStudent
     * @param TblStudentAgreementType $tblStudentAgreementType
     *
     * @return Service\Entity\TblStudentAgreement
     */
    public function insertStudentAgreement(
        TblStudent $tblStudent,
        TblStudentAgreementType $tblStudentAgreementType
    ) {

        return (new Data($this->getBinding()))->addStudentAgreement($tblStudent, $tblStudentAgreementType);
    }

    /**
     * @param        $Route
     * @param        $StationEntrance
     * @param        $StationExit
     * @param string $Remark
     *
     * @return TblStudentTransport
     */
    public function insertStudentTransport(
        $Route,
        $StationEntrance,
        $StationExit,
        $Remark = ''
    ) {

        return (new Data($this->getBinding()))->createStudentTransport(
            $Route,
            $StationEntrance,
            $StationExit,
            $Remark
        );
    }

    /**
     * @param TblPerson|null  $IntegrationPerson
     * @param TblCompany|null $IntegrationCompany
     * @param                 $CoachingRequestDate
     * @param                 $CoachingCounselDate
     * @param                 $CoachingDecisionDate
     * @param                 $CoachingRequired
     * @param                 $CoachingTime
     * @param string          $CoachingRemark
     *
     * @return Service\Entity\TblStudentIntegration
     */
    public function insertStudentIntegration(
        TblPerson $IntegrationPerson = null,
        TblCompany $IntegrationCompany = null,
        $CoachingRequestDate,
        $CoachingCounselDate,
        $CoachingDecisionDate,
        $CoachingRequired,
        $CoachingTime = '',
        $CoachingRemark = ''
    ) {

        return (new Data($this->getBinding()))->createStudentIntegration(
            $IntegrationPerson ? $IntegrationPerson : null,
            $IntegrationCompany ? $IntegrationCompany : null,
            $CoachingRequestDate,
            $CoachingCounselDate,
            $CoachingDecisionDate,
            $CoachingRequired,
            $CoachingTime,
            $CoachingRemark
        );
    }

    /**
     * @param TblPerson                    $tblPerson
     * @param string                       $Prefix
     * @param string                       $Identifier
     * @param TblStudentMedicalRecord|null $tblStudentMedicalRecord
     * @param TblStudentTransport|null     $tblStudentTransport
     * @param TblStudentBilling|null       $tblStudentBilling
     * @param TblStudentLocker|null        $tblStudentLocker
     * @param TblStudentBaptism|null       $tblStudentBaptism
     * @param TblStudentIntegration|null   $tblStudentIntegration
     * @param string                       $SchoolAttendanceStartDate
     *
     * @return TblStudent
     */
    public function createStudent(
        TblPerson $tblPerson,
        $Prefix = '',
        $Identifier = '',
        TblStudentMedicalRecord $tblStudentMedicalRecord = null,
        TblStudentTransport $tblStudentTransport = null,
        TblStudentBilling $tblStudentBilling = null,
        TblStudentLocker $tblStudentLocker = null,
        TblStudentBaptism $tblStudentBaptism = null,
        TblStudentIntegration $tblStudentIntegration = null,
        $SchoolAttendanceStartDate = ''
    ) {

        return (new Data($this->getBinding()))->createStudent($tblPerson,
            $Prefix,
            $Identifier,
            $tblStudentMedicalRecord,
            $tblStudentTransport,
            $tblStudentBilling,
            $tblStudentLocker,
            $tblStudentBaptism,
            $tblStudentIntegration,
            $SchoolAttendanceStartDate);
    }

    /**
     * @param TblStudent $tblStudent
     * @param $Prefix
     * @return bool|TblStudent
     */
    public function updateStudentPrefix(TblStudent $tblStudent, $Prefix)
    {

        return (new Data($this->getBinding()))->updateStudentPrefix($tblStudent,$Prefix);
    }

    /**
     * @param TblStudent $tblStudent
     * @param $Identifier
     * @return bool|TblStudent
     */
    public function updateStudentIdentifier(TblStudent $tblStudent, $Identifier)
    {

        return (new Data($this->getBinding()))->updateStudentIdentifier($tblStudent,$Identifier);
    }

    /**
     * @param IFormInterface $Form
     * @param TblPerson      $tblPerson
     * @param array          $Meta
     * @param                $Group
     *
     * @return IFormInterface|Redirect|string
     */
    public function createMeta(IFormInterface $Form = null, TblPerson $tblPerson, $Meta, $Group)
    {

        /**
         * Skip to Frontend
         */
        if (null === $Meta) {
            return $Form;
        }

        $tblStudent = $this->getStudentByPerson($tblPerson);

        $AttendingDoctor = Person::useService()->getPersonById($Meta['MedicalRecord']['AttendingDoctor']);
        $IntegrationPerson = Person::useService()->getPersonById($Meta['Integration']['School']['Person']);
        $IntegrationCompany = Company::useService()->getCompanyById($Meta['Integration']['School']['Company']);
        $SiblingRank = Relationship::useService()->getSiblingRankById($Meta['Billing']);

        $Prefix = $Meta['Student']['Prefix'];
        $Identifier = '';
        $tblSetting = Consumer::useService()->getSetting('People', 'Meta', 'Student', 'Automatic_StudentNumber');
        if($tblSetting && $tblSetting->getValue()){
            $biggestIdentifier = Student::useService()->getStudentMaxIdentifier();
            $Identifier = $biggestIdentifier + 1;
        }

        if ($tblStudent) {
            $Identifier = $tblStudent->getIdentifier();
            $tblStudentMedicalRecord = $tblStudent->getTblStudentMedicalRecord();
            if ($tblStudentMedicalRecord) {
                (new Data($this->getBinding()))->updateStudentMedicalRecord(
                    $tblStudent->getTblStudentMedicalRecord(),
                    $Meta['MedicalRecord']['Disease'],
                    $Meta['MedicalRecord']['Medication'],
                    $AttendingDoctor ? $AttendingDoctor : null,
                    $Meta['MedicalRecord']['Insurance']['State'],
                    $Meta['MedicalRecord']['Insurance']['Company']
                );
            } else {
                $tblStudentMedicalRecord = (new Data($this->getBinding()))->createStudentMedicalRecord(
                    $Meta['MedicalRecord']['Disease'],
                    $Meta['MedicalRecord']['Medication'],
                    $AttendingDoctor ? $AttendingDoctor : null,
                    $Meta['MedicalRecord']['Insurance']['State'],
                    $Meta['MedicalRecord']['Insurance']['Company']
                );
            }

            $tblStudentLocker = $tblStudent->getTblStudentLocker();
            if ($tblStudentLocker) {
                (new Data($this->getBinding()))->updateStudentLocker(
                    $tblStudent->getTblStudentLocker(),
                    $Meta['Additional']['Locker']['Number'],
                    $Meta['Additional']['Locker']['Location'],
                    $Meta['Additional']['Locker']['Key']
                );
            } else {
                $tblStudentLocker = (new Data($this->getBinding()))->createStudentLocker(
                    $Meta['Additional']['Locker']['Number'],
                    $Meta['Additional']['Locker']['Location'],
                    $Meta['Additional']['Locker']['Key']
                );
            }

            $tblStudentBaptism = $tblStudent->getTblStudentBaptism();
            if ($tblStudentBaptism) {
                (new Data($this->getBinding()))->updateStudentBaptism(
                    $tblStudent->getTblStudentBaptism(),
                    $Meta['Additional']['Baptism']['Date'],
                    $Meta['Additional']['Baptism']['Location']
                );
            } else {
                $tblStudentBaptism = (new Data($this->getBinding()))->createStudentBaptism(
                    $Meta['Additional']['Baptism']['Date'],
                    $Meta['Additional']['Baptism']['Location']
                );
            }

            $tblStudentTransport = $tblStudent->getTblStudentTransport();
            if ($tblStudentTransport) {
                (new Data($this->getBinding()))->updateStudentTransport(
                    $tblStudent->getTblStudentTransport(),
                    $Meta['Transport']['Route'],
                    $Meta['Transport']['Station']['Entrance'],
                    $Meta['Transport']['Station']['Exit'],
                    $Meta['Transport']['Remark']
                );
            } else {
                $tblStudentTransport = (new Data($this->getBinding()))->createStudentTransport(
                    $Meta['Transport']['Route'],
                    $Meta['Transport']['Station']['Entrance'],
                    $Meta['Transport']['Station']['Exit'],
                    $Meta['Transport']['Remark']
                );
            }

            $tblStudentIntegration = $tblStudent->getTblStudentIntegration();
            if ($tblStudentIntegration) {
                (new Data($this->getBinding()))->updateStudentIntegration(
                    $tblStudent->getTblStudentIntegration(),
                    $IntegrationPerson ? $IntegrationPerson : null,
                    $IntegrationCompany ? $IntegrationCompany : null,
                    $Meta['Integration']['Coaching']['RequestDate'],
                    $Meta['Integration']['Coaching']['CounselDate'],
                    $Meta['Integration']['Coaching']['DecisionDate'],
                    isset( $Meta['Integration']['Coaching']['Required'] ),
                    $Meta['Integration']['School']['Time'],
                    $Meta['Integration']['School']['Remark']
                );
            } else {
                $tblStudentIntegration = (new Data($this->getBinding()))->createStudentIntegration(
                    $IntegrationPerson ? $IntegrationPerson : null,
                    $IntegrationCompany ? $IntegrationCompany : null,
                    $Meta['Integration']['Coaching']['RequestDate'],
                    $Meta['Integration']['Coaching']['CounselDate'],
                    $Meta['Integration']['Coaching']['DecisionDate'],
                    isset( $Meta['Integration']['Coaching']['Required'] ),
                    $Meta['Integration']['School']['Time'],
                    $Meta['Integration']['School']['Remark']
                );
            }

            $tblStudentBilling = $tblStudent->getTblStudentBilling();
            if ($tblStudentBilling) {
                (new Data($this->getBinding()))->updateStudentBilling(
                    $tblStudentBilling,
                    $SiblingRank ? $SiblingRank : null
                );
            } else {
                $tblStudentBilling = (new Data($this->getBinding()))->createStudentBilling(
                    $SiblingRank ? $SiblingRank : null
                );
            }

            (new Data($this->getBinding()))->updateStudent(
                $tblStudent,
                $Prefix,
                $Identifier,
                $tblStudentMedicalRecord,
                $tblStudentTransport,
                $tblStudentBilling,
                $tblStudentLocker,
                $tblStudentBaptism,
                $tblStudentIntegration,
                $Meta['Student']['SchoolAttendanceStartDate'],
                isset($Meta['Student']['HasMigrationBackground']),
                isset($Meta['Student']['IsInPreparationDivisionForMigrants'])
            );

        } else {

            $tblStudentLocker = (new Data($this->getBinding()))->createStudentLocker(
                $Meta['Additional']['Locker']['Number'],
                $Meta['Additional']['Locker']['Location'],
                $Meta['Additional']['Locker']['Key']
            );

            $tblStudentMedicalRecord = (new Data($this->getBinding()))->createStudentMedicalRecord(
                $Meta['MedicalRecord']['Disease'],
                $Meta['MedicalRecord']['Medication'],
                $AttendingDoctor ? $AttendingDoctor : null,
                $Meta['MedicalRecord']['Insurance']['State'],
                $Meta['MedicalRecord']['Insurance']['Company']
            );

            $tblStudentBaptism = (new Data($this->getBinding()))->createStudentBaptism(
                $Meta['Additional']['Baptism']['Date'],
                $Meta['Additional']['Baptism']['Location']
            );

            $tblStudentTransport = (new Data($this->getBinding()))->createStudentTransport(
                $Meta['Transport']['Route'],
                $Meta['Transport']['Station']['Entrance'],
                $Meta['Transport']['Station']['Exit'],
                $Meta['Transport']['Remark']
            );

            $tblStudentIntegration = (new Data($this->getBinding()))->createStudentIntegration(
                $IntegrationPerson ? $IntegrationPerson : null,
                $IntegrationCompany ? $IntegrationCompany : null,
                $Meta['Integration']['Coaching']['RequestDate'],
                $Meta['Integration']['Coaching']['CounselDate'],
                $Meta['Integration']['Coaching']['DecisionDate'],
                isset( $Meta['Integration']['Coaching']['Required'] ),
                $Meta['Integration']['School']['Time'],
                $Meta['Integration']['School']['Remark']
            );

            $tblStudentBilling = (new Data($this->getBinding()))->createStudentBilling(
                $SiblingRank ? $SiblingRank : null
            );

            $tblStudent = (new Data($this->getBinding()))->createStudent(
                $tblPerson,
                $Prefix,
                $Identifier,
                $tblStudentMedicalRecord,
                $tblStudentTransport,
                $tblStudentBilling,
                $tblStudentLocker,
                $tblStudentBaptism,<commit_msg>Fix: #SSW-229 nachträgliches Ändern der Schülernummer<commit_after><?php
namespace SPHERE\Application\People\Meta\Student;

use SPHERE\Application\Corporation\Company\Company;
use SPHERE\Application\Corporation\Company\Service\Entity\TblCompany;
use SPHERE\Application\Education\Lesson\Division\Division;
use SPHERE\Application\Education\Lesson\Division\Service\Entity\TblDivision;
use SPHERE\Application\Education\Lesson\Division\Service\Entity\TblLevel;
use SPHERE\Application\Education\Lesson\Subject\Service\Entity\TblSubject;
use SPHERE\Application\Education\Lesson\Subject\Subject;
use SPHERE\Application\Education\Lesson\Term\Service\Entity\TblYear;
use SPHERE\Application\Education\Lesson\Term\Term;
use SPHERE\Application\Education\School\Course\Course;
use SPHERE\Application\Education\School\Type\Type;
use SPHERE\Application\People\Group\Group;
use SPHERE\Application\People\Meta\Student\Service\Data;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudent;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentAgreementType;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentBaptism;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentBilling;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentIntegration;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentLocker;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentMedicalRecord;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentSubject;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentSubjectRanking;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentSubjectType;
use SPHERE\Application\People\Meta\Student\Service\Entity\TblStudentTransport;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudent;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentAgreement;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentBaptism;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentDisorder;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentFocus;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentIntegration;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentLocker;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentMedicalRecord;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentTransfer;
use SPHERE\Application\People\Meta\Student\Service\Entity\ViewStudentTransport;
use SPHERE\Application\People\Meta\Student\Service\Service\Integration;
use SPHERE\Application\People\Meta\Student\Service\Setup;
use SPHERE\Application\People\Person\Person;
use SPHERE\Application\People\Person\Service\Entity\TblPerson;
use SPHERE\Application\People\Relationship\Relationship;
use SPHERE\Application\People\Relationship\Service\Entity\TblSiblingRank;
use SPHERE\Application\Setting\Consumer\Consumer;
use SPHERE\Common\Frontend\Form\IFormInterface;
use SPHERE\Common\Frontend\Message\Repository\Success;
use SPHERE\Common\Window\Redirect;

/**
 * Class Service
 *
 * @package SPHERE\Application\People\Meta\Student
 */
class Service extends Integration
{

    /**
     * @return false|ViewStudent[]
     */
    public function viewPerson()
    {

        return ( new Data($this->getBinding()) )->viewStudent();
    }

    /**
     * @return false|ViewStudentAgreement[]
     */
    public function viewStudentAgreement()
    {

        return ( new Data($this->getBinding()) )->viewStudentAgreement();
    }

    /**
     * @return false|ViewStudentBaptism[]
     */
    public function viewStudentBaptism()
    {

        return ( new Data($this->getBinding()) )->viewStudentBaptism();
    }

//    /**
//     * @return false|ViewStudentBilling[]
//     */
//    public function viewStudentBilling()
//    {
//
//        return (new Data($this->getBinding()))->viewStudentBilling();
//    }

    /**
     * @return false|ViewStudentDisorder[]
     */
    public function viewStudentDisorder()
    {

        return ( new Data($this->getBinding()) )->viewStudentDisorder();
    }

    /**
     * @return false|ViewStudentFocus[]
     */
    public function viewStudentFocus()
    {

        return ( new Data($this->getBinding()) )->viewStudentFocus();
    }

    /**
     * @return false|ViewStudentIntegration[]
     */
    public function viewStudentIntegration()
    {

        return ( new Data($this->getBinding()) )->viewStudentIntegration();
    }

    /**
     * @return false|ViewStudentIntegration[]
     */
    public function viewStudentLiberation()
    {

        return ( new Data($this->getBinding()) )->viewStudentLiberation();
    }

    /**
     * @return false|ViewStudentLocker[]
     */
    public function viewStudentLocker()
    {

        return ( new Data($this->getBinding()) )->viewStudentLocker();
    }

    /**
     * @return false|ViewStudentMedicalRecord[]
     */
    public function viewStudentMedicalRecord()
    {

        return ( new Data($this->getBinding()) )->viewStudentMedicalRecord();
    }

//    /**
//     * @return false|ViewStudentSubject[]
//     */
//    public function viewStudentSubject()
//    {
//
//        return ( new Data($this->getBinding()) )->viewStudentSubject();
//    }

    /**
     * @return false|ViewStudentTransfer[]
     */
    public function viewStudentTransfer()
    {

        return ( new Data($this->getBinding()) )->viewStudentTransfer();
    }

    /**
     * @return false|ViewStudentTransport[]
     */
    public function viewStudentTransport()
    {

        return ( new Data($this->getBinding()) )->viewStudentTransport();
    }

    /**
     * @param bool $doSimulation
     * @param bool $withData
     *
     * @return string
     */
    public function setupService($doSimulation, $withData)
    {

        $Protocol = (new Setup($this->getStructure()))->setupDatabaseSchema($doSimulation);
        if (!$doSimulation && $withData) {
            (new Data($this->getBinding()))->setupDatabaseContent();
        }
        return $Protocol;
    }

    /**
     * @param $LockerNumber
     * @param $LockerLocation
     * @param $KeyNumber
     *
     * @return TblStudentLocker
     */
    public function insertStudentLocker(
        $LockerNumber,
        $LockerLocation,
        $KeyNumber
    ) {

        return (new Data($this->getBinding()))->createStudentLocker(
            $LockerNumber,
            $LockerLocation,
            $KeyNumber
        );
    }

    /**
     * @param TblSiblingRank $tblSiblingRank
     *
     * @return TblStudentBilling
     */
    public function insertStudentBilling(TblSiblingRank $tblSiblingRank)
    {

        return (new Data($this->getBinding()))->createStudentBilling(
            $tblSiblingRank
        );
    }

    /**
     * @param                $Disease
     * @param                $Medication
     * @param                $Insurance
     * @param int|null       $InsuranceState
     * @param TblPerson|null $tblPersonAttendingDoctor
     *
     * @return TblStudentMedicalRecord
     */
    public function insertStudentMedicalRecord(
        $Disease,
        $Medication,
        $Insurance,
        $InsuranceState = 0,
        TblPerson $tblPersonAttendingDoctor = null
    ) {

        return (new Data($this->getBinding()))->createStudentMedicalRecord(
            $Disease,
            $Medication,
            $tblPersonAttendingDoctor,
            $InsuranceState,
            $Insurance
        );
    }

    /**
     * @param TblStudent              $tblStudent
     * @param TblStudentAgreementType $tblStudentAgreementType
     *
     * @return Service\Entity\TblStudentAgreement
     */
    public function insertStudentAgreement(
        TblStudent $tblStudent,
        TblStudentAgreementType $tblStudentAgreementType
    ) {

        return (new Data($this->getBinding()))->addStudentAgreement($tblStudent, $tblStudentAgreementType);
    }

    /**
     * @param        $Route
     * @param        $StationEntrance
     * @param        $StationExit
     * @param string $Remark
     *
     * @return TblStudentTransport
     */
    public function insertStudentTransport(
        $Route,
        $StationEntrance,
        $StationExit,
        $Remark = ''
    ) {

        return (new Data($this->getBinding()))->createStudentTransport(
            $Route,
            $StationEntrance,
            $StationExit,
            $Remark
        );
    }

    /**
     * @param TblPerson|null  $IntegrationPerson
     * @param TblCompany|null $IntegrationCompany
     * @param                 $CoachingRequestDate
     * @param                 $CoachingCounselDate
     * @param                 $CoachingDecisionDate
     * @param                 $CoachingRequired
     * @param                 $CoachingTime
     * @param string          $CoachingRemark
     *
     * @return Service\Entity\TblStudentIntegration
     */
    public function insertStudentIntegration(
        TblPerson $IntegrationPerson = null,
        TblCompany $IntegrationCompany = null,
        $CoachingRequestDate,
        $CoachingCounselDate,
        $CoachingDecisionDate,
        $CoachingRequired,
        $CoachingTime = '',
        $CoachingRemark = ''
    ) {

        return (new Data($this->getBinding()))->createStudentIntegration(
            $IntegrationPerson ? $IntegrationPerson : null,
            $IntegrationCompany ? $IntegrationCompany : null,
            $CoachingRequestDate,
            $CoachingCounselDate,
            $CoachingDecisionDate,
            $CoachingRequired,
            $CoachingTime,
            $CoachingRemark
        );
    }

    /**
     * @param TblPerson                    $tblPerson
     * @param string                       $Prefix
     * @param string                       $Identifier
     * @param TblStudentMedicalRecord|null $tblStudentMedicalRecord
     * @param TblStudentTransport|null     $tblStudentTransport
     * @param TblStudentBilling|null       $tblStudentBilling
     * @param TblStudentLocker|null        $tblStudentLocker
     * @param TblStudentBaptism|null       $tblStudentBaptism
     * @param TblStudentIntegration|null   $tblStudentIntegration
     * @param string                       $SchoolAttendanceStartDate
     *
     * @return TblStudent
     */
    public function createStudent(
        TblPerson $tblPerson,
        $Prefix = '',
        $Identifier = '',
        TblStudentMedicalRecord $tblStudentMedicalRecord = null,
        TblStudentTransport $tblStudentTransport = null,
        TblStudentBilling $tblStudentBilling = null,
        TblStudentLocker $tblStudentLocker = null,
        TblStudentBaptism $tblStudentBaptism = null,
        TblStudentIntegration $tblStudentIntegration = null,
        $SchoolAttendanceStartDate = ''
    ) {

        return (new Data($this->getBinding()))->createStudent($tblPerson,
            $Prefix,
            $Identifier,
            $tblStudentMedicalRecord,
            $tblStudentTransport,
            $tblStudentBilling,
            $tblStudentLocker,
            $tblStudentBaptism,
            $tblStudentIntegration,
            $SchoolAttendanceStartDate);
    }

    /**
     * @param TblStudent $tblStudent
     * @param $Prefix
     * @return bool|TblStudent
     */
    public function updateStudentPrefix(TblStudent $tblStudent, $Prefix)
    {

        return (new Data($this->getBinding()))->updateStudentPrefix($tblStudent,$Prefix);
    }

    /**
     * @param TblStudent $tblStudent
     * @param $Identifier
     * @return bool|TblStudent
     */
    public function updateStudentIdentifier(TblStudent $tblStudent, $Identifier)
    {

        return (new Data($this->getBinding()))->updateStudentIdentifier($tblStudent,$Identifier);
    }

    /**
     * @param IFormInterface $Form
     * @param TblPerson      $tblPerson
     * @param array          $Meta
     * @param                $Group
     *
     * @return IFormInterface|Redirect|string
     */
    public function createMeta(IFormInterface $Form = null, TblPerson $tblPerson, $Meta, $Group)
    {

        /**
         * Skip to Frontend
         */
        if (null === $Meta) {
            return $Form;
        }

        $tblStudent = $this->getStudentByPerson($tblPerson);

        $AttendingDoctor = Person::useService()->getPersonById($Meta['MedicalRecord']['AttendingDoctor']);
        $IntegrationPerson = Person::useService()->getPersonById($Meta['Integration']['School']['Person']);
        $IntegrationCompany = Company::useService()->getCompanyById($Meta['Integration']['School']['Company']);
        $SiblingRank = Relationship::useService()->getSiblingRankById($Meta['Billing']);

        $Prefix = $Meta['Student']['Prefix'];
        $tblSetting = Consumer::useService()->getSetting('People', 'Meta', 'Student', 'Automatic_StudentNumber');
        if($tblSetting && $tblSetting->getValue()){
            $biggestIdentifier = Student::useService()->getStudentMaxIdentifier();
            $Meta['Student']['Identifier'] = $biggestIdentifier + 1;
        }

        if ($tblStudent) {
            $tblStudentMedicalRecord = $tblStudent->getTblStudentMedicalRecord();
            if ($tblStudentMedicalRecord) {
                (new Data($this->getBinding()))->updateStudentMedicalRecord(
                    $tblStudent->getTblStudentMedicalRecord(),
                    $Meta['MedicalRecord']['Disease'],
                    $Meta['MedicalRecord']['Medication'],
                    $AttendingDoctor ? $AttendingDoctor : null,
                    $Meta['MedicalRecord']['Insurance']['State'],
                    $Meta['MedicalRecord']['Insurance']['Company']
                );
            } else {
                $tblStudentMedicalRecord = (new Data($this->getBinding()))->createStudentMedicalRecord(
                    $Meta['MedicalRecord']['Disease'],
                    $Meta['MedicalRecord']['Medication'],
                    $AttendingDoctor ? $AttendingDoctor : null,
                    $Meta['MedicalRecord']['Insurance']['State'],
                    $Meta['MedicalRecord']['Insurance']['Company']
                );
            }

            $tblStudentLocker = $tblStudent->getTblStudentLocker();
            if ($tblStudentLocker) {
                (new Data($this->getBinding()))->updateStudentLocker(
                    $tblStudent->getTblStudentLocker(),
                    $Meta['Additional']['Locker']['Number'],
                    $Meta['Additional']['Locker']['Location'],
                    $Meta['Additional']['Locker']['Key']
                );
            } else {
                $tblStudentLocker = (new Data($this->getBinding()))->createStudentLocker(
                    $Meta['Additional']['Locker']['Number'],
                    $Meta['Additional']['Locker']['Location'],
                    $Meta['Additional']['Locker']['Key']
                );
            }

            $tblStudentBaptism = $tblStudent->getTblStudentBaptism();
            if ($tblStudentBaptism) {
                (new Data($this->getBinding()))->updateStudentBaptism(
                    $tblStudent->getTblStudentBaptism(),
                    $Meta['Additional']['Baptism']['Date'],
                    $Meta['Additional']['Baptism']['Location']
                );
            } else {
                $tblStudentBaptism = (new Data($this->getBinding()))->createStudentBaptism(
                    $Meta['Additional']['Baptism']['Date'],
                    $Meta['Additional']['Baptism']['Location']
                );
            }

            $tblStudentTransport = $tblStudent->getTblStudentTransport();
            if ($tblStudentTransport) {
                (new Data($this->getBinding()))->updateStudentTransport(
                    $tblStudent->getTblStudentTransport(),
                    $Meta['Transport']['Route'],
                    $Meta['Transport']['Station']['Entrance'],
                    $Meta['Transport']['Station']['Exit'],
                    $Meta['Transport']['Remark']
                );
            } else {
                $tblStudentTransport = (new Data($this->getBinding()))->createStudentTransport(
                    $Meta['Transport']['Route'],
                    $Meta['Transport']['Station']['Entrance'],
                    $Meta['Transport']['Station']['Exit'],
                    $Meta['Transport']['Remark']
                );
            }

            $tblStudentIntegration = $tblStudent->getTblStudentIntegration();
            if ($tblStudentIntegration) {
                (new Data($this->getBinding()))->updateStudentIntegration(
                    $tblStudent->getTblStudentIntegration(),
                    $IntegrationPerson ? $IntegrationPerson : null,
                    $IntegrationCompany ? $IntegrationCompany : null,
                    $Meta['Integration']['Coaching']['RequestDate'],
                    $Meta['Integration']['Coaching']['CounselDate'],
                    $Meta['Integration']['Coaching']['DecisionDate'],
                    isset( $Meta['Integration']['Coaching']['Required'] ),
                    $Meta['Integration']['School']['Time'],
                    $Meta['Integration']['School']['Remark']
                );
            } else {
                $tblStudentIntegration = (new Data($this->getBinding()))->createStudentIntegration(
                    $IntegrationPerson ? $IntegrationPerson : null,
                    $IntegrationCompany ? $IntegrationCompany : null,
                    $Meta['Integration']['Coaching']['RequestDate'],
                    $Meta['Integration']['Coaching']['CounselDate'],
                    $Meta['Integration']['Coaching']['DecisionDate'],
                    isset( $Meta['Integration']['Coaching']['Required'] ),
                    $Meta['Integration']['School']['Time'],
                    $Meta['Integration']['School']['Remark']
                );
            }

            $tblStudentBilling = $tblStudent->getTblStudentBilling();
            if ($tblStudentBilling) {
                (new Data($this->getBinding()))->updateStudentBilling(
                    $tblStudentBilling,
                    $SiblingRank ? $SiblingRank : null
                );
            } else {
                $tblStudentBilling = (new Data($this->getBinding()))->createStudentBilling(
                    $SiblingRank ? $SiblingRank : null
                );
            }

            (new Data($this->getBinding()))->updateStudent(
                $tblStudent,
                $Prefix,
                $Meta['Student']['Identifier'],
                $tblStudentMedicalRecord,
                $tblStudentTransport,
                $tblStudentBilling,
                $tblStudentLocker,
                $tblStudentBaptism,
                $tblStudentIntegration,
                $Meta['Student']['SchoolAttendanceStartDate'],
                isset($Meta['Student']['HasMigrationBackground']),
                isset($Meta['Student']['IsInPreparationDivisionForMigrants'])
            );

        } else {

            $tblStudentLocker = (new Data($this->getBinding()))->createStudentLocker(
                $Meta['Additional']['Locker']['Number'],
                $Meta['Additional']['Locker']['Location'],
                $Meta['Additional']['Locker']['Key']
            );

            $tblStudentMedicalRecord = (new Data($this->getBinding()))->createStudentMedicalRecord(
                $Meta['MedicalRecord']['Disease'],
                $Meta['MedicalRecord']['Medication'],
                $AttendingDoctor ? $AttendingDoctor : null,
                $Meta['MedicalRecord']['Insurance']['State'],
                $Meta['MedicalRecord']['Insurance']['Company']
            );

            $tblStudentBaptism = (new Data($this->getBinding()))->createStudentBaptism(
                $Meta['Additional']['Baptism']['Date'],
                $Meta['Additional']['Baptism']['Location']
            );

            $tblStudentTransport = (new Data($this->getBinding()))->createStudentTransport(
                $Meta['Transport']['Route'],
                $Meta['Transport']['Station']['Entrance'],
                $Meta['Transport']['Station']['Exit'],
                $Meta['Transport']['Remark']
            );

            $tblStudentIntegration = (new Data($this->getBinding()))->createStudentIntegration(
                $IntegrationPerson ? $IntegrationPerson : null,
                $IntegrationCompany ? $IntegrationCompany : null,
                $Meta['Integration']['Coaching']['RequestDate'],
                $Meta['Integration']['Coaching']['CounselDate'],
                $Meta['Integration']['Coaching']['DecisionDate'],
                isset( $Meta['Integration']['Coaching']['Required'] ),
                $Meta['Integration']['School']['Time'],
                $Meta['Integration']['School']['Remark']
            );

            $tblStudentBilling = (new Data($this->getBinding()))->createStudentBilling(
                $SiblingRank ? $SiblingRank : null
            );

            $tblStudent = (new Data($this->getBinding()))->createStudent(
                $tblPerson,
                $Prefix,
                $Meta['Student']['Identifier'],
                $tblStudentMedicalRecord,
                $tblStudentTransport,
                $tblStudentBilling,
                $tblStudentLocker,
                $tblStudentBaptism,
{'fraction_non_alphanumeric': 0.13246577578768162, 'fraction_numerical': 0.00016325007579467805, 'mean_word_length': 2.310174463486182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 218, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2355894', 'n_tokens_mistral': 11523, 'n_tokens_neox': 10924, 'n_words': 1527}