<?php

namespace Modules\MembershipApplication\Transformers;

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

class MembershipApplicationResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'application_number' => $this->application_number,
            'status' => $this->status?->value ?? $this->status,
            'board_result' => $this->board_result ?: null,
            'submitted_at' => $this->submitted_at,
            'completed_at' => $this->completed_at ?: null,
            'applicant' => new MembershipApplicationApplicantResource($this->whenLoaded('applicant')),
            'heirs' => MembershipApplicationHeirResource::collection($this->whenLoaded('heirs')),
            'references' => MembershipApplicationReferenceResource::collection($this->whenLoaded('references')),
            'documents' => MembershipApplicationDocumentResource::collection($this->whenLoaded('documents')),
            'reviews' => MembershipApplicationReviewResource::collection($this->whenLoaded('reviews')),
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
        ];
    }
}
