<?php
use App\Models\Menu;
use App\Models\MenuGroup;

if (!function_exists('apiResponse')) {
    /**
     * Standard API JSON response
     *
     * @param bool $status
     * @param string $message
     * @param mixed|null $data
     * @param int $code
     * @return \Illuminate\Http\JsonResponse
     */
    function apiResponse($status, $message, $data = null, $code = 200)
    {
        $response = [
            'status' => $status,
            'message' => $message,
        ];

        if (!is_null($data)) {
            $response['data'] = $data;
        }

        return response()->json($response, $code);
    }
}

if (! function_exists('DatatableResponse')) {
    function DatatableResponse($data,$totalRecord,$draw = null,$params=null)
    {
        $response_arr = [];
        $response_arr['data'] = $data;
        $response_arr['recordsTotal'] = $totalRecord;
        $response_arr['recordsFiltered'] = $totalRecord;
        $response_arr['param'] = $params;
        $response_arr['draw'] = $draw;

        return response()->json($response_arr);
    }
}



if (! function_exists('getMenu')) {
    function getMenu()
    {
        $menus = Menu::where('route','<>', '#')->get();
        return $menus;
    }
}


if (! function_exists('getMenuGrp')) {
    function getMenuGrp()
    {
        $menus = MenuGroup::where('status', '1')->get();
        return $menus;
    }
}
