<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Course extends Model
{
    protected $fillable = [
        'name',
        'code',
        'duration_months',
        'status',
    ];

    // Helper: initials from course name (e.g. "Web Development" → "WD")
    public function getInitialsAttribute(): string
    {
        $words = explode(' ', $this->name);
        return strtoupper(implode('', array_map(fn($w) => $w[0] ?? '', array_slice($words, 0, 2))));
    }

    // Badge class for status
    public function getBadgeClassAttribute(): string
    {
        return match($this->status) {
            'Active'   => 'badge-green',
            'Upcoming' => 'badge-amber',
            'Inactive' => 'badge-slate',
            default    => 'badge-slate',
        };
    }
}
