<?php

namespace App\Services;

use App\Interface\NoteOwner;
use App\Models\Note;

class NoteService {

    public function __construct(HistoryService $historyService) {
        $this->historyService = $historyService;
    }

    public function addNote(NoteOwner $owner, string $note, $is_primary = false) {
        $owner->notes()->create([
            'user_id' => auth()->id(),
            'note' => $note,
            'is_primary' => $is_primary
        ]);

        if($is_primary) {
            $this->historyService->add($owner, "New Key Info Added: " . $note);
        } else {
            $this->historyService->add($owner, "New Note Added: " . $note);
        }
    }

    public function deleteNote(Note $note) {
        if($note->is_primary) {
            $this->historyService->add($note->owner, "Key Info Deleted: " . $note->note);
        } else {
            $this->historyService->add($note->owner, "Note Deleted: " . $note->note);
        }
        $note->delete();
    }
}