<?php

namespace App\Domains\Event\Actions\SignUp;

use App\Enumerations\EatingHabit;
use App\Enumerations\EfzStatus;
use App\ValueObjects\Age;
use Illuminate\Support\Str;

class SignUpCommand {
    public function __construct(public SignUpRequest $request) {
    }

    public function execute() : SignUpResponse {
        $response = new SignUpResponse();

        $eatingHabit = match ($this->request->eating_habit) {
            'vegan' => EatingHabit::EATING_HABIT_VEGAN,
            'vegetarian' => EatingHabit::EATING_HABIT_VEGETARIAN,
            default => EatingHabit::EATING_HABIT_OMNIVOR,
        };

        $participantAge = new Age($this->request->birthday);
        $response->participant = $this->request->event->participants()->create(
            [
                'tenant' => $this->request->event->tenant,
                'user_id' => $this->request->user_id,
                'identifier' => Str::random(10),
                'firstname' => $this->request->firstname,
                'lastname' => $this->request->lastname,
                'nickname' => $this->request->nickname,
                'participation_type' => $this->request->participationType,
                'local_group' => $this->request->localGroup->slug,
                'birthday' => $this->request->birthday,
                'address_1' => $this->request->address_1,
                'address_2' => $this->request->address_2,
                'postcode' => $this->request->postcode,
                'city' => $this->request->city,
                'email_1' => $this->request->email_1,
                'email_2' => $this->request->email_2,
                'phone_1' => $this->request->phone_1,
                'phone_2' => $this->request->phone_2,
                'contact_person' => $this->request->contact_person,
                'allergies' => $this->request->allergies,
                'intolerances' => $this->request->intolerances,
                'medications' => $this->request->medications,
                'tetanus_vaccination' => $this->request->tetanus_vaccination,
                'eating_habit' => $eatingHabit,
                'swimming_permission' => $participantAge->isfullAged() ? 'SWIMMING_PERMISSION_ALLOWED' : $this->request->swimming_permission,
                'first_aid_permission' => $participantAge->isfullAged() ? 'FIRST_AID_PERMISSION_ALLOWED' : $this->request->first_aid_permission,
                'foto_socialmedia' => $this->request->foto_socialmedia,
                'foto_print' => $this->request->foto_print,
                'foto_webseite' => $this->request->foto_webseite,
                'foto_partner' => $this->request->foto_partner,
                'foto_intern' => $this->request->foto_intern,
                'arrival_date' => $this->request->arrival,
                'departure_date' => $this->request->departure,
                'arrival_eating' => $this->request->arrival_eating,
                'departure_eating' => $this->request->departure_eating,
                'notes' => $this->request->notes,
                'amount' => $this->request->amount,
                'payment_purpose' => $this->request->event->name . ' - Beitrag ' . $this->request->firstname . ' ' . $this->request->lastname,
                'efz_status' => $participantAge->isfullAged() ? EfzStatus::EFZ_STATUS_NOT_CHECKED : EfzStatus::EFZ_STATUS_NOT_REQUIRED,
            ]
        );

        $response->success = true;
        return $response;
    }

}
