<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Resources\Json\JsonResource;

class PermissionResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id'          => $this->id,
            'scope'       => $this->scope,
            'description' => $this->description,
            'bits'        => $this->bits,
            'parent_id'   => $this->parent_id,
            'created_at'  => Carbon::parse($this->created_at)->format('Y-m-d H:i'),
            'updated_at'  => Carbon::parse($this->updated_at)->format('Y-m-d H:i'),
        ];
    }

    public static function collection($resource): AnonymousResourceCollection
    {
        return parent::collection($resource);
    }
}
