<?php

namespace App\GraphQL\Mutations;

use App\Exports\GraduatedTraineesReport;
use App\Exports\TraineesPersonalDataReport;
use App\Models\StudentEducational;
use Illuminate\Support\Facades\File;
use Maatwebsite\Excel\Facades\Excel;

class ExportDiscontinuedTraineesData
{
    /**
     * @param null $_
     * @param array<string, mixed> $args
     */
    public function __invoke($_, array $args): string
    {
        $from = @$args['from_date'];
        $to = @$args['to_date'];
        // $students = StudentEducational::where('')->with('student.user')->get();
        $students = StudentEducational::withoutGlobalScopes()
            ->whereHas('student', function ($query) use ($from, $to) {
                $query->withoutGlobalScopes()->where('status', '!=', 1);
                if ($from) {
                    $query->where('updated_at', '>=', $from);
                }
                if ($to) {
                    $query->where('updated_at', '<=', $to);
                }
           })
            ->with('user')
            ->get();


        return view('reports.dismissedTraineee', compact('students'))->render();
    }
}
