<?php

namespace App\Http\Controllers\API;

use App\Models\User;
use App\Http\Controllers\Controller;

class AgentController extends Controller
{
    public function getBalance()
    {
        /** @var User $user */
        $user = auth()->user();
        $balance = $user->balance;
        return response()->success('Successfully get balance.',  compact('balance'));
    }

    public function getAgentData()
    {
        /** @var User $user */
        $user = auth()->user();
        $data = [
            'today' => [
                'total_winning_amount' => $user->totalWinningAmount('today'),
                'total_loss_amount' => $user->totalLossAmount('today'),
                'total_betting_amount' => $user->totalBettingAmount('today'),
                'total_commission_amount' => $user->totalCommissionAmount('today'),
            ],
            'last3days' => [
                'total_winning_amount' => $user->totalWinningAmount('last3days'),
                'total_loss_amount' => $user->totalLossAmount('last3days'),
                'total_betting_amount' => $user->totalBettingAmount('last3days'),
                'total_commission_amount' => $user->totalCommissionAmount('last3days'),
            ],
            'all' => [
                'total_winning_amount' => $user->totalWinningAmount(),
                'total_loss_amount' => $user->totalLossAmount(),
                'total_betting_amount' => $user->totalBettingAmount(),
                'total_commission_amount' => $user->totalCommissionAmount(),
            ]
        ];
        return response()->success('Successfully get agent data.', compact('data'));
    }

    public function getTransactions()
    {
        /** @var User $user */
        $user = auth()->user();
        $transactions = $user->transactions()->latest('id')->get();

        return response()->success('Successfully get transactions.', compact('transactions'));
    }
}
