<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class LeadNote extends Model
{
    protected $fillable = ['lead_id', 'added_by', 'avatar_color', 'via', 'note'];

    public function lead()
    {
        return $this->belongsTo(Lead::class);
    }

    public function getInitialsAttribute()
    {
        $parts = explode(' ', $this->added_by);
        return strtoupper(substr($parts[0], 0, 1) . (isset($parts[1]) ? substr($parts[1], 0, 1) : ''));
    }

    public static function viaBadge($via)
    {
        $map = [
            'Phone Call' => 'b-call',
            'WhatsApp'   => 'b-whatsapp',
            'Email'      => 'b-email',
            'Meeting'    => 'b-positive',
            'Walk-in'    => 'b-new',
            'Note'       => 'b-new',
        ];
        return $map[$via] ?? 'b-new';
    }
}
