<?php

namespace App\Http\Controllers;

use App\Models\Lead;
use App\Models\LeadNote;
use Illuminate\Http\Request;

class LeadNoteController extends Controller
{
    public function store(Request $req, Lead $lead)
    {
        $req->validate(['note' => 'required|string']);

        LeadNote::create([
            'lead_id'      => $lead->id,
            'added_by'     => 'Admin',
            'avatar_color' => '#1a73e8',
            'via'          => $req->via ?? 'Note',
            'note'         => $req->note,
        ]);

        $lead->update(['last_contact' => now()]);

        return back()->with('success', 'Note added.');
    }

    public function destroy(Lead $lead, LeadNote $note)
    {
        $note->delete();
        return back()->with('success', 'Note deleted.');
    }
}
