<?php

namespace App\Http\Controllers;

use App\Services\MainAccountPickerService;

class MainAccountPickerController extends Controller
{
    public function resolve(int $id)
    {
        return response()->json(app(MainAccountPickerService::class)->resolve($id));
    }

    public function index()
    {
        return response()->json(
            app(MainAccountPickerService::class)->allMainAccounts()
                ->map(fn ($account) => [
                    'id' => $account->id,
                    'label' => "[{$account->account_code}] {$account->account_name}",
                    'has_subs' => $account->has_subs,
                ])
        );
    }
}
