<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Shareholder extends Model
{
    protected $fillable = [
        'name', 'phone', 'email', 'address',
        'total_investment', 'total_withdrawal',
        'total_profit', 'total_profit_withdrawal',
        'is_active',
    ];

    public function transactions()
    {
        return $this->hasMany(ShareholderTransaction::class)->orderByDesc('transaction_date');
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    public function getNetInvestmentAttribute(): float
    {
        return $this->total_investment - $this->total_withdrawal;
    }

    public function getNetProfitAttribute(): float
    {
        return $this->total_profit - $this->total_profit_withdrawal;
    }
}
