<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Anggota;
use App\Models\Deposito;
use App\Models\Kas;
use App\Models\PenempatanBank;
use App\Models\Tabungan;

class DashboardController extends Controller
{
    public function index()
    {
        $anggota = Anggota::where('status', 1)->get();
        $tabungan = Tabungan::where('status', 1)->get();
        $deposito = Deposito::where('status', 1)->get();
        $kas = Kas::where('status', 1)->get();
        $penempatan = PenempatanBank::where('status', 1)->get();


        return response()->json([
            'anggota' => $anggota->count(),
            'tabungan' => $tabungan->count(),
            'saldo_tabungan' => $tabungan->sum('saldo'),
            'deposito' => $deposito->count(),
            'saldo_deposito' => $deposito->sum('nilai_valuta'),
            'kas' => $kas->count(),
            'saldo_kas' => $kas->sum('saldo'),
            'penempatan' => $penempatan->count(),
            'saldo_penempatan' => $penempatan->sum('saldo'),
        ]);
    }
}
