<?php

namespace App\Http\Resources\Archives;

use App\Http\Resources\ImageResource;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class ArchiveResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'slug' => $this->slug,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'label' => $this->label,
            'archiveMonth' => $this->archive_date ? Carbon::parse($this->archive_date)->format('m') : null,
            'archiveYear' => $this->archive_date ? Carbon::parse($this->archive_date)->format('Y') : null,
            'image' => new ImageResource($this->image),
        ];
    }
}
