<?php

namespace App\Services\Cartables\SafetyAndPrivacy;

use App\Exceptions\ProhibitedAction;
use App\Facades\DataTable\DataTableFacade;
use App\Models\SafetyAndPrivacy;
use Illuminate\Http\Request;
use Throwable;

class SupervisorService
{
    /**
     * @throws Throwable
     */
    public function dataTable(Request $request)
    {
        $user = auth()->user();

        $query = SafetyAndPrivacy::query();

        if ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province'))
        {
            throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));

            $query = $query->where('province_id', '=', $user->province_id);
        }

        return DataTableFacade::run(
            $query,
            $request,
            allowedFilters: ['*'],
            allowedSortings: ['*'],
            allowedSelects: [
                'id','lat','lon', 'recognize_picture','action_picture','created_at','status', 'final_description', 'province_fa',
                'info_fa', 'activity_date_time', 'action_picture_document_upload_date', 'judiciary_document_upload_date',
                'edare_shahri_name', 'step_fa', 'axis_type_id', 'axis_type_name', 'action_date', 'is_finished', 'status_fa',
                'supervisor_description', 'operator_description'
            ]
        );
    }
}