<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class ManagedInvestmentPlan extends Model
{
    protected $fillable = [
        'name',
        'max_amount',
        'min_amount',
        'min_roi_percent',
        'max_roi_percent',
        'gift_bonus',
        'topup_interval',
        'topup_type',
        'topup_amount',
        'investment_duration',
        'description',
        'is_active',
        'sort_order',
    ];

    protected $casts = [
        'max_amount' => 'decimal:2',
        'min_amount' => 'decimal:2',
        'min_roi_percent' => 'decimal:4',
        'max_roi_percent' => 'decimal:4',
        'gift_bonus' => 'decimal:2',
        'topup_amount' => 'decimal:4',
        'is_active' => 'boolean',
        'sort_order' => 'integer',
    ];

    public function subscriptions(): HasMany
    {
        return $this->hasMany(ManagedInvestmentSubscription::class);
    }

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