<?php

namespace App\Http\Controllers\Wallets;

use App\Classes\ValueObjects\Response\ApiResponseObject;
use App\Classes\ValueObjects\Constants\HttpStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Transaction;
use App\Models\Wallet;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class WalletReportController
{
    public function walletsReport(Request $request): JsonResponse
    {
        return (new ApiResponseObject(
            'fetch service report Successful',
            '',
            HttpStatus::OK_WITH_MESSAGE,
            ['data' => [
                'walletSum' => (float) Wallet::all()->sum('amount'),
                'outgoingSum' =>  (float) Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Wallet::class)->sum('amount'),
                'incomingSum' =>  (float) Transaction::whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE])->where('owner_type', Wallet::class)->sum('amount'),
            ]]
        ))->handler();
    }
}
