<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use App\Models\Deposit;
use App\Models\Withdrawal;
use App\Models\User;
use App\Models\Plan;

class Investment extends Model
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'plan_id',
        'duration',
        'balance',
        'pfit',
        'f_pfit',
        'moved',
        'moved_record',
        'buy_date',
        'end_date',
        'user_id',
        'is_paused',
        'trade_min',
        'trade_max',
        'amount',
        'funded',
        'status',
        'is_settled',
        'pause_time',
    ];
    
    protected $casts = [
        'moved_record' => 'array',
    ];

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

    public function plan()
    {
        return $this->belongsTo(Plan::class);
    }

    public function deposit()
    {
        return $this->hasMany(Deposit::class);
    }

    public function sells()
    {
        return $this->hasMany(Sell::class);
    }

    public function bids()
    {
        return $this->hasMany(Bid::class);
    }

    public function ownerships()
    {
        return $this->hasMany(Ownership::class);
    }

    public function withdrawal()
    {
        return $this->hasMany(Withdrawal::class);
    }

    public function inTransaction()
    {
        return $this->hasMany(In_transaction::class);
    }
}
