<?php

namespace App\Http\Resources;


use Illuminate\Http\Resources\Json\JsonResource;

class VoucherCampaignResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $metadata = null;
        if ($request->has('include_metadata')) {
            $metadata = KeyValueBasicResource::collection($this->attributesKVP()->latest()->get());
        }

        return [
            // 'id' => $this->id,
            'campaign_id' => $this->campaign_id,
            'name' => $this->name,
            'slug' => $this->slug,
            'description' => $this->description,
            'limit_per_month' => $this->limit_per_month,
            'metadata' => $metadata
        ];
    }
}
