<?php

namespace App\Models;

use CodeIgniter\Model;

class ModelDashboard extends Model
{
    // Method untuk mengambil statistik balita, ibu hamil, dan lansia secara umum
    public function getStatistics($table)
    {
        return $this->builder($table)
            ->select('COUNT(*) as total')
            ->get()
            ->getRowArray();
    }

    // Method untuk mengambil data per bulan berdasarkan created_at
    public function getMonthlyData($table)
    {
        return $this->builder($table)
            ->select('YEAR(created_at) as year, MONTH(created_at) as month, COUNT(*) as total')
            ->groupBy('YEAR(created_at), MONTH(created_at)')
            ->orderBy('YEAR(created_at), MONTH(created_at)', 'ASC')
            ->get()
            ->getResultArray();
    }
}
