/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Resources/Pages/Resource/PurposeResource.php
<?php
namespace App\Http\Resources\Pages\Resource;

use App\Helpers\ResourceHelper;
use App\Http\Resources\Pages\Blog\PostCollection;
use App\Models\Post;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;

/**
 * @OA\Schema(title="PurposeResource",description="Post resource",
 *     @OA\Xml(name="PurposeResource")
 * )
 */
class PurposeResource extends JsonResource
{

    /**
     * @OA\Property(property="description", type="string", example="<p>Wuxal R Max / Wuxal MacroMix / Wuxal Universal Active treatments provide plants with essential macro and microelements for rapid growth and development, increase tillering productivity.</p>"),
     */
    public string|null $language;
    public string|null $country;
    public array|null $data;

    public function language($value): static
    {
        $this->language = $value;
        return $this;
    }

    public function country($value): static
    {
        $this->country = $value;
        return $this;
    }

    public function __construct($resource)
    {
        parent::__construct($resource);
        $this->data = $resource['attributes'];
    }



    public function toArray(Request $request): array
    {
        return [
            'description' => ResourceHelper::getValue($this->data['description'] ?? null, $this->country, $this->language),
        ];
    }

    public static function collection($resource): PostCollection
    {
        return new PostCollection($resource);
    }
}