<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class OfferResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'offer_to' => $this->offer_to,
            'product_id' => $this->product_id,
            'project_id' => $this->project_id,
            'name' => $this->name,
            'description' => $this->description,
            'offer_type' => $this->offer_type,
            'contract_type' => $this->contract_type,
            'price' => $this->price !== null ? (float) $this->price : null,
            'amount' => $this->price !== null ? (float) $this->price : null,
            'quantity' => $this->quantity,
            'unit' => $this->unit,
            'offer_date' => $this->offer_date?->toISOString(),
            'expiry_date' => $this->expiry_date?->toISOString(),
            'contract_start_date' => $this->contract_start_date?->toDateString(),
            'contract_end_date' => $this->contract_end_date?->toDateString(),
            'duration_days' => $this->duration_days,
            'status' => $this->status,
            'specifications' => $this->specifications,
            'notes' => $this->notes,
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
            'user' => new UserResource($this->whenLoaded('user')),
            'project' => new ProjectSummaryResource($this->whenLoaded('project')),
            'product' => new ProductResource($this->whenLoaded('product')),
        ];
    }
}
