<?php

class NotificationBlast extends \Phalcon\Mvc\Model
{

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var string
     */
    public $judul;

    /**
     *
     * @var string
     */
    public $konten;

    /**
     *
     * @var string
     */
    public $keterangan;

    /**
     *
     * @var string
     */
    public $parameter;

    /**
     *
     * @var string
     */
    public $created_at;

    /**
     *
     * @var string
     */
    public $updated_at;

    /**
     *
     * @var string
     */
    public $deleted_at;

    /**
     *
     * @var integer
     */
    public $user_id;

    /**
     *
     * @var integer
     */
    public $tenant_id;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("jaga");
        $this->setSource("notification_blast");
        $this->belongsTo('user_id', '\UmUser', 'um_id', ["alias" => "umUser"]);
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'notification_blast';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return NotificationBlast[]|NotificationBlast|\Phalcon\Mvc\Model\ResultSetInterface
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return NotificationBlast|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public function listJsonDetail(){
        $result = $this->toArray();
        $result["user"] = [
            "user_id" => $this->user_id,
            "nama" => $this->umUser->nama
        ];
        return $result;
    }

    public function getJsonErrMessages(){
        $res = [];
        foreach($this->getMessages() as $message ){
            $res[] = [
                "type" => $message->getType(),
                "field" => $message->getField(),
                "message" => $message->getMessage(),
            ];
        }
        return $res;
    }

}
