<?php

namespace App\Domains\Dashboard\Controllers;

use App\Domains\Dashboard\Actions\UpdatePersonalData\UpdatePersonalDataCommand;
use App\Domains\Dashboard\Actions\UpdatePersonalData\UpdatePersonalDataRequest;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class StorePersonalDataController extends CommonController
{
    public function __invoke(Request $request): JsonResponse
    {
        $user = auth()->user();

        $actionRequest = new UpdatePersonalDataRequest(
            user:               $user,
            nickname:           $request->input('nickname'),
            email:              $request->input('email'),
            phone:              $request->input('phone'),
            address1:           $request->input('address1'),
            address2:           $request->input('address2'),
            postcode:           $request->input('postcode'),
            city:               $request->input('city'),
            medications:        $request->input('medications'),
            allergies:          $request->input('allergies'),
            intolerances:       $request->input('intolerances'),
            eatingHabits:       $request->input('eatingHabits'),
            swimmingPermission: $request->input('swimmingPermission'),
            firstAidPermission: $request->input('firstAidPermission'),
            bankAccountOwner:   $request->input('bankAccountOwner'),
            bankAccountIban:    $request->input('bankAccountIban'),
            birthday:           $request->input('birthday'),
            tetanusVaccination: $request->input('tetanusVaccination'),
        );

        $command  = new UpdatePersonalDataCommand($actionRequest, $this->users);
        $command->execute();

        return response()->json(['success' => true, 'message' => 'Deine Daten wurden erfolgreich gespeichert.']);
    }
}
