<?php

namespace App\Http\Resources\Api;

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

abstract class BaseResource extends JsonResource
{
    public bool $forShow = false;

    public function forShow(): static
    {
        $this->forShow = true;

        return $this;
    }

    public function toArray(Request $request): array
    {
        return $this->forShow ? $this->forShowData() : $this->defaultData();
    }

    abstract protected function defaultData(): array;

    abstract protected function forShowData(): array;

    protected function imageUrl(?string $path): ?string
    {
        return $path ? asset('storage/' . $path) : null;
    }
}
