<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Mtc\ContentManager\Contracts\MediaUse;
use Mtc\ContentManager\Http\Resources\MediaEntryResource;

class DealAddOnResource extends JsonResource
{
    public static $wrap = '';

    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $this->resource->load(['conditions', 'mediaUses.media']);
        $resource = parent::toArray($request);
        $resource['media'] = $this->resource->mediaUses->pluck('media_id');
        $resource['media_uses'] = $this->resource->mediaUses
            ->map(fn(MediaUse $mediaUse) => new MediaEntryResource($mediaUse));
        return $resource;
    }
}
