<?php

namespace App\Models;

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

class InvestmentInterest extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_investment_id',
        'user_id',
        'amount',
        'rate',
        'period',
        'calculated_at',
        'credited_at',
        'status',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'rate' => 'decimal:2',
        'calculated_at' => 'datetime',
        'credited_at' => 'datetime',
    ];

    /**
     * Relations
     */
    public function investment()
    {
        return $this->belongsTo(UserInvestment::class, 'user_investment_id');
    }

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

    /**
     * Scopes
     */
    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }

    public function scopeCredited($query)
    {
        return $query->where('status', 'credited');
    }
}
