<?php

namespace App\Http\Resources\Api\V1;

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

class PermissionResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $parts = explode('.', $this->name);

        return [
            'id' => $this->id,
            'name' => $this->name,
            'module' => $parts[0] ?? null,
            'action' => $parts[1] ?? null,
            'created_at' => $this->created_at,
        ];
    }
}
