<?php

namespace App\Http\Resources\Opportunity;

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

class ActivityDetalleResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'description' => $this->description,
            'scheduled_at' => $this->scheduled_at,
            'completed_at' => $this->completed_at,
            'state_activity' => $this->state_activity,
            'type_activity_id' => $this->type_activity_id,
            'type_activity' => $this->type_activity->name,
            'opportunity_id' => $this->opportunity_id,
            'assigned_to' => $this->assigned_to,
            'entity_status' => $this->entity_status,
            'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
            'project_name' => $this->opportunity->property? $this->opportunity->property->project->title:null,
            'property_title' => $this->opportunity->property? $this->opportunity->property->title:null,
            'code_property' => $this->opportunity->property? $this->opportunity->property->code:null,
            'price' => $this->opportunity->property? $this->opportunity->property->base_price:null,
            'stage' => $this->opportunity->stage->title? $this->opportunity->stage->title:null,
            'name_opportunity' => $this->opportunity->customer->name? $this->opportunity->customer->name:null,
            'phone_opportunity' => $this->opportunity->customer->phone? $this->opportunity->customer->phone:null,
        ];
    }
}
