<?php

namespace App\Http\Resources;

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

class PlanResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'plan_id'              => $this->plan_id,
            'plan_name'            => $this->plan_name,
            'is_active'            => $this->is_active,
            'plan_description'     => $this->plan_description,
            'plan_applicable_for'  => $this->plan_applicable_for,
            'plan_eful_code'       => $this->plan_eful_code,

            // ── Highlight / Marketing Card Block ──────────────────────────
            'highlight_card' => [
                'brand_name'         => $this->highlight_brand_name,
                'starting_price_pkr' => $this->highlight_starting_price
                                          ? (float) $this->highlight_starting_price
                                          : null,
                'starting_price_fmt' => $this->highlight_starting_price
                                          ? 'Starting from Rs. ' . number_format($this->highlight_starting_price, 0) . '/- Yearly'
                                          : null,
                'features'           => $this->highlight_features ?? [],
            ],

            'products_count'       => $this->whenCounted('products'),
            'products'             => ProductResource::collection($this->whenLoaded('products')),
            'created_at'           => $this->created_at?->toISOString(),
            'updated_at'           => $this->updated_at?->toISOString(),
        ];
    }
}