<?php 

namespace App\Services; 

use App\Package;
use App\Services\common\QueryService;
use Illuminate\Http\Request;


Class PackageService
{
    private function conditionQuery(Request $request){
        $packages = Package::query()->orderBy('id','DESC');
        $columnQueryRules=[
            'logistic_number' => ['like' => ''],
            'batch_number' => ['like' => ''],
            'created_at_start' => ['alias' => 'created_at','startDate' => " 00:00:00"],
            'created_at_end' => ['alias' => 'created_at','endDate' => " 23:59:59"],
        ];
        $packages = app(QueryService::class)->query($request,$packages,$columnQueryRules);
        return $packages;
    }

    public function paginate(Request $request){
        $packages = $this->conditionQuery($request);
        return $packages->paginate($request->paginate ?? 50);
    }

    public function get(Request $request){
        $packages = $this->conditionQuery($request);
        return $packages->get();
    }

    public function some(Request $request){
        return Package::query()->orderBy('id','DESC')
            ->whereIn('id',explode(',',$request->data))->get();
    }

}