<?php

namespace App\Controllers;

use App\Models\ClassAttendanceModel;
use App\Models\ClassModel;
use App\Models\ClassTypeModel;
use App\Models\PaymentModel;
use App\Models\StudentModel;

class Dashboard extends BaseController
{
    public function index()
    {
        $data['title'] = 'Dashboard';

        $model = new ClassTypeModel();
        $studentModel = new StudentModel();
        $classModel = new ClassModel();
        $paymentModel = new PaymentModel();



        $data['activeStudentCount'] = $studentModel->getActiveCount();
        $data['activeClassCount'] = $classModel->getActiveCount();
        $data['currentMonthTotal'] = $paymentModel->getCurrentMonthTotal();

        $data['classTypes'] = $model->whereIn('status', [1, 2])->orderBy('created_datetime', 'DESC')->findAll();

        return view('dashboard', $data);
    }
    public function getMonthlyIncome()
    {
        $paymentModel = new PaymentModel();

        $data = $paymentModel->getMonthlyIncome();

        return $this->response->setJSON($data);
    }

    public function getPendingPayments()
    {
        $paymentModel = new PaymentModel();

        return $this->response->setJSON([
            'data' => $paymentModel->getAllPendingPayments()
        ]);
    }
}