<?php

namespace MGModule\DNSManager2\models\custom\reverse;
use MGModule\DNSManager2 as main;
use MGModule\DNSManager2\mgLibs\custom\dns\record\interfaces\ArrayPrinter;
/**
 * 
 * 
 * @Table(name=reverse)
 */
class Reverse extends main\mgLibs\models\orm implements ArrayPrinter {
    /**
     * ID field
     * 
     * @Column(id)
     * @var int 
     */
    public $id;
    
    /**
     *
     * @Column(int=11,uniqueKey=1)
     * @var int 
     */
    public $serverid;
    
    /**
     *
     * @Column(int=11)
     * @var int 
     */
    public $clientid;

    /**
     *
     * @Column(int=1)
     * @var int
     */
    public $type;

    /**
     *
     * @Column(int=11)
     * @var int
     */
    public $relid;
    
    /**
     *
     * @Column(varchar,isKey=1)
     * @var string 
     */
    public $from;
    
    /**
     *
     * @Column(varchar,isKey=1)
     * @var string 
     */
    public $sub;
    
    /**
     *
     * @Column(varchar)
     * @var string 
     */
    public $name;
    
    /**
     *
     * @Column(varchar,uniqueKey=1,isKey=1)
     * @var string 
     */
    public $ip;
    
    /**
     *
     * @Column(varchar)
     * @var string 
     */
    public $ttl;
    
    /**
     *
     * @Column(datetime)
     * @var string 
     */
    public $created_at;
    
    public static function byServerIDAndIP($serverid, $ip) {
        return Repository::factory()->byServerID($serverid)->byIP($ip)->one();
    }

    public function getServer() {
        return new main\models\custom\server\Server($this->serverid);
    }
    
    public function getFullDomain() {
        return ($this->sub?$this->sub . '.':'') . $this->from;
    }
    
    /** @return main\mgLibs\custom\dns\SubmoduleAbstract */
    public function getModule() {
        $module = $this->getServer()->getModule();
        $module->setDomain($this->from);
        return $module;
    }
}
