<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Client extends Model
{
    protected $fillable = [
        'client_id', 'name', 'phone', 'fb_page', 'status', 
        'deposited', 'spent', 'scopes', 'portal_key'
    ];

    protected $casts = [
        'scopes' => 'array',
        'deposited' => 'decimal:2',
        'spent' => 'decimal:2'
    ];

    public function meetings()
    {
        return $this->hasMany(Meeting::class, 'client_id', 'client_id');
    }

    public function spendingLogs()
    {
        return $this->hasMany(SpendingLog::class, 'client_id', 'client_id');
    }

    public function getBalanceAttribute()
    {
        return $this->deposited - $this->spent;
    }
}
