<?php

namespace App\Http\Resources;

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

class SubscriptionMemberResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'member_id'               => $this->member_id,
            'subscription_id'         => $this->subscription_id,
            'member_type'             => $this->member_type,
            'member_type_label'       => ucfirst($this->member_type),
            'is_self'                 => $this->is_self,

            // ── Personal info ──────────────────────────────────────────────
            'full_name'               => $this->full_name,
            'dob'                     => $this->dob?->format('Y-m-d'),
            'gender'                  => $this->gender,
            'cnic'                    => $this->cnic,
            'mobile'                  => $this->mobile,

            // ── Pricing ───────────────────────────────────────────────────
            'pricing' => [
                'age_in_months'          => $this->age_in_months,
                'age_in_years'           => $this->age_in_years,
                'contribution_age_group' => $this->contribution_age_group,
                'premium_pkr'            => (float) $this->premium,
                'premium_fmt'            => 'Rs. ' . number_format($this->premium, 0) . '/-',
                'premium_paisa'          => $this->premium_paisa,
            ],

            'is_active'  => $this->is_active,
            'created_at' => $this->created_at?->toISOString(),
        ];
    }
}