<?php

namespace App\Http\Resources;

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

class ContributionResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'receipt_number' => $this->receipt_number,
            'group' => new AjoGroupResource($this->whenLoaded('group')),
            'member' => new MemberResource($this->whenLoaded('member')),
            'amount_due_minor' => $this->amount_due,
            'amount_paid_minor' => $this->amount_paid,
            'outstanding_minor' => $this->outstanding_amount,
            'status' => $this->status->value,
            'due_date' => $this->due_date?->toDateString(),
            'payment_date' => $this->payment_date?->toISOString(),
            'payment_method' => $this->payment_method,
        ];
    }
}
