<?php

namespace App\Http\Resources;

use App\Classes\ValueObjects\Constants\SegmentConstants;
use Illuminate\Http\Resources\Json\JsonResource;

class SegmentResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $constant = $this->constants->where('reference', SegmentConstants::CUSTOM_PRICE)->first();
        return [
            'id' => $this->id,
            'name' => $this->name,
            'price' => $constant ? $constant->value[0] : 0
        ];
    }
}
