<?php

namespace App\Http\Resources\Customer;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class CustomerResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
    return [
        'id' => $this->id,
        'name' => $this->name,
        'email' => $this->email,
        'ci' => $this->ci,
        'cod_phone' => $this->cod_phone,
        'phone' => $this->phone,
        'thread' => $this->thread,
        'type_customer' => $this->type_customer,
        'date_of_birthday'=> $this->date_of_birthday,
        'workplace'=> $this->workplace,
        'lastOpportunity' => $this->opportunities()->whereNull('end_date')->first()->stage->title,
        'opportunity_id' => $this->opportunities()->whereNull('end_date')->first()->id,
        'property_id' => $this->opportunities()->whereNull('end_date')->first()->property_id,
        'property' => $this->opportunities()->whereNull('end_date')->first()->property,


    ];
    }
}
