<?php

namespace App\Resources;

use App\Models\EventParticipantAddon;
use Illuminate\Http\Resources\Json\JsonResource;

class EventParticipantAddonResource extends JsonResource
{
    function __construct(EventParticipantAddon $addon)
    {
        parent::__construct($addon);
    }

    public function toArray($request): array
    {
        return [
            'addonKey' => $this->resource->addon_key,
            'title' => $this->resource->title,
            'flat' => $this->resource->flat,
            'amount' => $this->resource->amount?->getAmount() ?? 0,
            'amountReadable' => $this->resource->amount?->toString() ?? '0,00 Euro',
            'free' => ($this->resource->amount?->getAmount() ?? 0) <= 0,
        ];
    }
}
