<?php

namespace App\Modules\CRM\Resources;

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

class LeadResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'customer_id' => $this->customer_id,
            'name' => $this->name,
            'company_name' => $this->company_name,
            'email' => $this->email,
            'phone' => $this->phone,
            'source' => $this->source,
            'stage' => $this->stage,
            'deal_value' => $this->deal_value,
            'next_follow_up_at' => optional($this->next_follow_up_at)->format('Y-m-d'),
            'notes' => $this->notes,
            'status' => $this->status,
            'activities' => $this->whenLoaded('activities', fn () => ActivityResource::collection($this->activities)),
        ];
    }
}
