<?php

namespace App\Http\Controllers\V3\Dashboard;

use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\InfoItem;
use Illuminate\Http\JsonResponse;

class ItemsManagementController extends Controller
{
    use ApiResponse;

    public function getItems(): JsonResponse
    {
        return $this->successResponse(
            InfoItem::query()
                ->select('item as id', 'item_str as name', 'icon')
                ->where('type', '=', 'item')
                ->groupby('item')
                ->get()
        );
    }

    public function getSubItems($item): JsonResponse
    {
        return $this->successResponse(
            InfoItem::query()
                ->where('item', '=', $item)
                ->select('id', 'item', 'item_str', 'sub_item_str as name', 'sub_item_unit as unit', 'needs_image', 'needs_end_point', 'sub_item')
                ->get()
        );
    }
}
