<?php

namespace App\Http\Controllers;

use App\Traits\QueryTrait;
use App\Traits\UserLoggedTrait;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, ValidatesRequests;
    use QueryTrait, UserLoggedTrait;

    protected $CHANNEL = null;
    protected $UTF_ENCODING = null;
    protected $fields = [
        'status' => 'available',
        'visible' => 'visible',
        'employee' => 'has_employee'
    ];

    public function __construct()
    {
        $this->UTF_ENCODING = config('app.UTF_ENCODING');
    }

    protected function updateBooleanStatus($request, $entity, $type = 'status')
    {
        $entity->update([
            $this->fields[$type] => $request->{$this->fields[$type]},
            'fk_userupdater' => $this->user()->id,
        ]);
    }

    protected function getUserGroups()
    {
        $usergroups = $this->user()->user_groups;
        $groupIds = $usergroups->pluck('group.id')->toArray();

        return $groupIds;
    }
}
