<?php

namespace App\Models;

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

class SavingsPlan extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'duration_months',
        'interest_rate',
        'min_amount',
        'is_active',
        'description'
    ];

    protected $casts = [
        'interest_rate' => 'decimal:2',
        'min_amount' => 'decimal:2',
        'is_active' => 'boolean'
    ];

    /**
     * Plans actifs seulement
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true)->orderBy('duration_months');
    }

    /**
     * Obtenir l'icône du plan
     */
    public function getIconAttribute()
    {
        $icons = [
            1 => '🌱',
            3 => '🌿',
            6 => '🌳',
            12 => '🏆'
        ];
        
        return $icons[$this->duration_months] ?? '💰';
    }

    /**
     * Obtenir la couleur du plan
     */
    public function getColorAttribute()
    {
        $colors = [
            1 => 'success',
            3 => 'info',
            6 => 'warning',
            12 => 'danger'
        ];
        
        return $colors[$this->duration_months] ?? 'primary';
    }
}
