<?php

namespace App\Http\Resources;

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

class BootstrapResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'user' => new UserResource($this['user']),
            'roles' => $this['roles']->map(fn ($role) => $role->only(['id', 'name', 'slug'])),
            'branches' => $this['branches']->map(fn ($branch) => $branch->only(['id', 'name', 'code', 'is_active'])),
            'payment_methods' => $this['payment_methods']->map(fn ($method) => $method->only(['id', 'name', 'type', 'is_active'])),
            'tax_rates' => $this['tax_rates']->map(fn ($taxRate) => $taxRate->only(['id', 'name', 'rate', 'is_default', 'is_inclusive'])),
            'categories' => $this['categories']->map(fn ($category) => $category->only(['id', 'name', 'slug', 'parent_id'])),
            'expense_categories' => $this['expense_categories']->map(fn ($cat) => $cat->only(['id', 'name'])),
            'units' => $this['units']->map(fn ($unit) => $unit->only(['id', 'name', 'abbreviation'])),
            'currencies' => $this['currencies']->map(fn ($currency) => $currency->only(['id', 'code', 'name', 'symbol', 'exchange_rate', 'is_base'])),
            'open_shift' => $this['open_shift'] ? new ShiftResource($this['open_shift']) : null,
        ];
    }
}
