<?php

namespace App\Http\Resources\Magazine;

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

class MagazineCategoryResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        //number of items can be (article or events) in each category
        $out = [
            'id' => $this->id,
            'name' => $this->title,
            'slug' => $this->slug,
            'isEventCategory' => $this->is_event_category,
            'content' => $this->content,
            'numberOfItems' => $this->is_event_category
                ? Event::full()->where('status', 'published')->count()
                : $this->articles_count,
        ];

        return $out;
    }
}
