<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

/**
 * @mixin Group
 */
class GroupRowResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'type' => $this->type,
            'branch_name' => $this->whenLoaded('branch', fn () => $this->branch?->name),
            'is_organization_wide' => $this->branch_id === null,
            'is_active' => $this->is_active,
            'members_count' => $this->whenCounted('members'),
        ];
    }
}
