<?php

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

/**
 * Log class
 * 
 * @Table(name=set)
 */
class Set extends main\mgLibs\models\orm {
    /**
     * ID field
     * 
     * @Column(id)
     * @var int 
     */
    public $id;
    
    /**
    *  
    * @Column(int=11, refrence=models\whmcs\clients\client::id)
    * @var int 
    */
    public $idu;
    
    /**
     *
     * @Column(varchar)
     * @var string 
     */
    public $name;
    
    /**
    *
    * @Column(varchar)
    * @var string 
    */
    public $default;
    
    public function getRecords($id = false) {
        return $id === false ? record\Repository::factory()->bySetID($this->id)->get()
                : record\SetRecord::factory($id);
    }
    
    public function setRecord($name, $type, $ttl, $rdata, $id = false) {
        if($id === false || !$record = $this->getRecords($id)) {
            $record = new record\SetRecord();
        }
        $record->setid = $this->id;
        $record->name = $name;
        $record->type = $type;
        $record->ttl = $ttl;
        $record->rdata = $rdata;
        $record->save();
        return $record;
    }
    
    public function delete() {
        record\Repository::factory()->bySetID($this->id)->delete();
        parent::delete();
    }
}
