<?php

namespace App\Transformers\Products;

use App\Models\Products\Product;
use App\Transformers\Applications\ApplicationTransformer;
use League\Fractal\Resource\Collection;
use League\Fractal\TransformerAbstract;

class ProductTransformer extends TransformerAbstract {
    protected array $defaultIncludes = [];

    protected array $availableIncludes = [
        'applications'
    ];

    public function transform(Product $model): array {
        return [
            'id' => $model->uuid,
            'name' => $model->name,
            'purpose' => $model->purpose,
            'usage' => $model->usage,
            'normative' => $model->normative,
            'producer' => $model->producer
        ];
    }

    public function includeApplications(Product $model): Collection {
        return $this->collection($model->applications, new ApplicationTransformer());
    }

}