<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Betting extends Model
{
    use HasFactory;

    protected $fillable = ['game_id', 'name', 'agent_id'];

    public function details()
    {
        return $this->hasMany(BettingDetail::class, 'betting_id');
    }

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('m/d/Y h:i A');
    }

    public function getTotalAmountAttribute()
    {
        return $this->details()->sum('amount');
    }

    public function getTotalWinningsAttribute()
    {
        return $this->details()->sum('winnings');
    }

    public function agent()
    {
        return $this->belongsTo(User::class);
    }

    public function game()
    {
        return $this->belongsTo(Game::class);
    }
}
