<?php

namespace App\Services;

use App\Models\Asset;
use App\Models\Expense;
use App\Models\Loan; 
use App\Models\Wallet; 

class StatementOfFinancialPosition
{
    
    public function cashAmount(): float
    {
        return (float) Wallet::sum('balance'); 
    }

  
    public function loansAmount(): float
    {
        return (float) Loan::where('loan_status', ['active', 'damaged'])->sum('repayment_amount');
    }


    public function equipmentAmount(): float
    {
        return (float) Asset::whereIn('status', ['active', 'damaged'])->sum('net_book_value');
    }

   
    public function totalAssets(): float
    {
        return $this->cashAmount() + $this->loansAmount() + $this->equipmentAmount();
    }

    
    public function totalLiabilities(): float
    {
        return (float) Expense::sum('expense_amount');
    }

    
    public function totalEquity(): float
    {
        return $this->totalAssets() - $this->totalLiabilities();
    }

   
    public function getReportData(): array
    {
        return [
            'cashAmount' => $this->cashAmount(),
            'loansAmount' => $this->loansAmount(),
            'equipmentAmount' => $this->equipmentAmount(),
            'totalAssets' => $this->totalAssets(),
            'totalLiabilities' => $this->totalLiabilities(),
            'totalEquity' => $this->totalEquity(),
        ];
    }
}
