<?php

namespace App\Domains\Dashboard\Controllers;

use App\Providers\InertiaProvider;
use App\Scopes\CommonController;

class PersonalDataController extends CommonController
{
    public function __invoke()
    {
        if (!$this->checkAuth()) {
            return redirect()->intended('/login');
        }

        $user = auth()->user();
        $data = $this->users->getPersonalData($user);

        $inertiaProvider = new InertiaProvider('Dashboard/PersonalData', [
            'personalData' => [
                'firstname'          => $data['firstname'],
                'lastname'           => $data['lastname'],
                'birthday'           => $data['birthday'],
                'nickname'           => $data['nickname'],
                'email'              => $data['email'],
                'phone'              => $data['phone'],
                'address1'           => $data['address_1'],
                'address2'           => $data['address_2'],
                'postcode'           => $data['postcode'],
                'city'               => $data['city'],
                'medications'        => $data['medications'],
                'allergies'          => $data['allergies'],
                'intolerances'       => $data['intolerances'],
                'eatingHabits'       => $data['eating_habits'],
                'swimmingPermission' => $data['swimming_permission'],
                'firstAidPermission' => $data['first_aid_permission'],
                'bankAccountOwner'   => $data['bank_account_owner'],
                'bankAccountIban'    => $data['bank_account_iban'],
                'tetanusVaccination' => $data['tetanus_vaccination'],
            ],
        ]);

        return $inertiaProvider->render();
    }
}
