<?php

namespace App\Http\Controllers;

use App\Jobs\ProcessEclatJob;
use App\Models\Proses;
use App\Models\Transaksi;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class ProsesController extends Controller
{
    public function index()
    {
        return view('layouts.pages.algoritma');
    }

    public function filter(Request $request)
    {
        $tanggal_dari = $request->input('tanggal_dari');
        $tanggal_sampai = $request->input('tanggal_sampai');
        $min_support = $request->input('min_support');
        $min_confidance = $request->input('min_confidance');

        $proses = Proses::create([
            'start' => $tanggal_dari,
            'end' => $tanggal_sampai,
            'min_support' => $min_support,
            'min_confidence' => $min_confidance,
        ]);

        $transaksi = Transaksi::whereBetween('tanggal', [$tanggal_dari, $tanggal_sampai])->get();
        $totalTransactions = $transaksi->count();

        ProcessEclatJob::dispatch($proses, $transaksi, $min_support, $min_confidance, $totalTransactions);

        return redirect()->back()->with('message', 'Silahkan tunggu data sedang diproses di latar belakang');
    }
}
