<?php

namespace App\Models;

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

class JointInvestmentTransaction extends Model
{
    use HasFactory;

    protected $fillable = [
        'joint_investment_id',
        'participant_id',
        'user_id',
        'transaction_type', // contribution, withdrawal, profit_distribution, fee
        'amount',
        'description',
        'status', // pending, completed, failed, cancelled
        'processed_at',
        'reference_id',
        'fee_amount',
        'balance_before',
        'balance_after'
    ];

    protected $casts = [
        'processed_at' => 'datetime',
        'fee_amount' => 'decimal:2'
    ];

    public function jointInvestment()
    {
        return $this->belongsTo(JointInvestment::class);
    }

    public function participant()
    {
        return $this->belongsTo(JointInvestmentParticipant::class);
    }

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

    public function getIsContributionAttribute()
    {
        return $this->transaction_type === 'contribution';
    }

    public function getIsWithdrawalAttribute()
    {
        return $this->transaction_type === 'withdrawal';
    }

    public function getIsProfitDistributionAttribute()
    {
        return $this->transaction_type === 'profit_distribution';
    }
} 