<?php

namespace App\Http\Resources\Quote;

use App\Http\Resources\Sales\SalesPropertyResource;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;

class QuoteResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'social_reason' => $this->social_reason,
            'nit' => $this->nit,
            'address' => $this->address,
            'phone' => $this->phone,
            'landline' => $this->landline,
            'percentage_initial_fee' => $this->percentage_initial_fee,
            'email' => $this->email,
            'workplace' => $this->workplace,
            'expiration_date' => $this->expiration_date ? Carbon::parse($this->expiration_date)->format('d-m-Y') : null,
            'creation_date' => $this->creation_date,
            'observations' => $this->observations,
            'status' => $this->status,
            'status_customer' => $this->status_customer,
            'payment_method' => $this->payment_method,
            'contract_signing_date' => $this->contract_signing_date ? Carbon::parse($this->contract_signing_date)->format('d-m-Y') : null,
            'amount' => $this->amount,
            'initial_fee' => $this->initial_fee,
            'balance' => $this->balance,
            'is_payment_initial_fee' => $this->is_payment_initial_fee,
            'discount' => $this->discount,
            'user_id' => $this->user_id,
            'customer_id' => $this->customer_id,
            'opportunity_id' => $this->opportunity_id,
            'created_at' => $this->created_at ? Carbon::parse($this->created_at)->format('d-m-Y') : null,
            'properties' => SalesPropertyResource::collection($this->Property),
        ];
    }
}
