<?php

namespace App\Services\Cartables\Mission;

use App\Enums\MissionStates;
use App\Facades\DataTable\DataTableFacade;
use App\Models\Mission;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class TransportationUnitService
{
    public function dataTable(Request $request)
    {
        $query = Mission::query()
            ->where('state_id', '=', MissionStates::REQUEST_CREATED->value)
            ->where('edare_shahri_name', '=', Auth::user()->edarate_shahri_id);

        return DataTableFacade::run(
            $query,
            $request,
            allowedFilters: ['*'],
            allowedSortings: ['*'],
            allowedSelects: [
                'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
                'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id',
                'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time'
            ]
        );
    }
}