<?php

namespace Modules\User\Repositories;

use Illuminate\Http\Request;
use Modules\User\Interfaces\ModuleRepositoryInterface;
use Modules\User\Models\Module;

class ModuleRepository implements ModuleRepositoryInterface
{
    public function get(Request $request)
    {
        $query = Module::query();

        if ($request->date_from) {
            $query->whereDate('created_at', '>=', $request->date_from);
        }

        if ($request->date_to) {
            $query->whereDate('created_at', '<=', $request->date_to);
        }


        if ( !is_null($request->status) && $request->status == 0) {
            $query->onlyTrashed();
        }

        if ($request->paginate ?? null) {
            $users= $query->paginate(50);
        }else{
            $users=$query->cursor();
        }

        return $users;
    }
}
