<?php

namespace App\Http\Controllers;

use App\Repositories\UtilsRepository;
use Illuminate\Http\Request;


class UtilsController extends Controller {
    public function __construct() {
        $this->middleware('auth:api', ['except' => []]);
    }

    public function question(Request $request) {
        try {
            //1. Query params
            $box_id = ($request->box_id) ? $request->box_id : null;
            $company_id = ($request->company_id) ? $request->company_id : null;

            //2. Authorize
            if ($box_id) auth()->user()->authorize("box_admin", $box_id);
            else if ($company_id) auth()->user()->authorize("company_admin", $company_id);
            else auth()->user()->authorize("super_admin");

            //3. Retrieve
            $params = [
                "company_id" => $request->company_id,
                "box_id" => $request->box_id,
                "user_id" => $request->user_id,
                "name" => $request->name,
                "mobile" => $request->mobile,
                "email" => $request->email,
                "subject" => $request->subject,
                "msg" => $request->msg
            ];
            $result = UtilsRepository::question(auth()->user()->id, $params);
        } catch (\Exception $e) {
            return $e->getMessage();
        }
        return response()->json($result,200);

    }
}
