<?php

namespace MGModule\DNSManager2\mgLibs\custom\manager;

use MGModule\DNSManager2\models\custom\notification;

class NotificationHelper {
    public static function addProblemNotification($message) {
        self::addNotification(notification\NotificationTypeEnum::ERROR, $message);
    }
    
    public static function addInfoNotification($message, $name = notification\NotificationNameEnum::OTHER) {
        self::addNotification(notification\NotificationTypeEnum::INFO, $message, $name);
    }
    
    private static function addNotification($type, $message, $name = notification\NotificationNameEnum::OTHER) {
        $notification = new notification\Notification();
        $notification->name = $name;
        $notification->date = date('Y-m-d H:i:s');
        $notification->read = 0;
        $notification->type = $type;
        $notification->value = $message;
        $notification->save();
    }
    
    public static function readNotificationByID($notification_id) {
        self::readNotification(new notification\Notification($notification_id));
    }
    
    public static function readNotification($notification) {
        $notification->read = 1;
        $notification->save();
    }
}