<?php

namespace MGModule\DNSManager2\models\custom\notification;
use MGModule\DNSManager2 as main;

/**
 * Log class
 * 
 * @Table(name=notification)
 */
class Notification extends main\mgLibs\models\orm{
    /**
     * ID field
     * 
     * @Column(id)
     * @var int 
     */
    public $id;
    
    /**
     *
     * @Column(varchar)
     * @var string 
     */
    public $name;
    
    /**
     *
     * @Column(text)
     * @var string 
     */
    public $value;
    
    /**
     * 
     * @Column(int)
     * @var string 
     */
    public $type;
    
    /**
     *
     * @Column(int)
     * @var string 
     */
    public $read;
    
    /**
     *
     * @Column(datetime)
     * @var string 
     */
    public $date;
    //TODO: wywalic setType (sprawdzic czy nie uzywane)
    public function setType($type) {
        if(!NotificationTypeEnum::isValidValue($type))
            throw new Exception ("Wrong type provided");
        $this->type = $type;
    }
    
    public function save($data = array()) {
        if(!NotificationTypeEnum::isValidValue($this->type)) {
            throw new \Exception('Invalid Notification Type');
        }
        
        if(!NotificationNameEnum::isValidValue($this->name)) {
            throw new \Exception('Invalid Notification Name');
        }
        parent::save($data);
    }
}
