<?php

declare(strict_types=1);

namespace App\Http\Resources;

use App\Models\Member;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * A member row as seen through a group's membership list — includes the
 * group_member pivot fields.
 *
 * @mixin Member
 */
class GroupMemberResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'member_number' => $this->member_number,
            'full_name' => trim("{$this->first_name} {$this->last_name}"),
            'membership_status' => $this->membership_status,
            'photo_thumb_url' => $this->photo_path ? "/api/v1/members/{$this->id}/photo?size=thumb" : null,
            'role_in_group' => $this->pivot->role_in_group,
            'joined_at' => $this->pivot->joined_at?->toDateString(),
        ];
    }
}
