<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

/**
 * @mixin Branch
 */
class BranchResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'region_id' => $this->region_id,
            'region_name' => $this->whenLoaded('region', fn () => $this->region?->name),
            'name' => $this->name,
            'code' => $this->code,
            'city' => $this->city,
            'phone' => $this->phone,
            'email' => $this->email,
            'pastor_name' => $this->pastor_name,
            'is_active' => $this->is_active,
            'members_count' => $this->when(isset($this->members_count), $this->members_count),
        ];
    }
}
