<?php

namespace common\models;

use Yii;
use yii\helpers\Url;
use yii\helpers\VarDumper;
use common\models\BaseFitnessActiveRecord;
use yii\helpers\Console;

/**
 * This is the model class for table "log".
 *
 * @property integer $id_log
 * @property integer $type
 * @property string $message
 * @property string $url
 * @property string $app
 * @property integer $id_user
 * @property integer $id_transfer
 * @property integer $id_money_movement
 * @property integer $id_ticket
 * @property integer $id_sale
 * @property integer $id_customer
 * @property integer $id_account
 * @property integer $id_account_state
 * @property integer $id_key
 * @property integer $id_product
 * @property integer $id_door_log
 * @property string $created_at
 * @property string $updated_at
 */
class Log extends BaseFitnessActiveRecord
{
   
	public static $TYPE_INFO = 10;
	public static $TYPE_ERR = 20;
	public static $TYPE_TICKET_USAGE_FIRST = 30;
	public static $TYPE_TICKET_USAGE_MULTIPLE = 40;
	public static $TYPE_LOGIN = 50;
	public static $TYPE_DEFAULT_ACCOUNT= 60;
	public static $TYPE_CREATE_CUSTOMER= 70;
	public static $TYPE_PROCUREMENT_UPDATE = 80;
	public static $TYPE_TICKET_COUNT_MOVE_OUT = 90;
	public static $TYPE_WASTE = 100;
	/**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'log';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id_log' => Yii::t('common/log', 'Azonosító'),
            'type' => Yii::t('common/log', 'Típus'),
            'message' => Yii::t('common/log', 'Üzenet'),
            'url' => Yii::t('common/log', 'Url'),
            'app' => Yii::t('common/log', 'Alkalmazás'),
            'id_user' => Yii::t('common/log', 'Felhasználó'),
            'id_transfer' => Yii::t('common/log', 'Tranzakció'),
            'id_money_movement' => Yii::t('common/log', 'Pénzmozgás'),
            'id_ticket' => Yii::t('common/log', 'Bérlet'),
            'id_sale' => Yii::t('common/log', 'Termékeladás'),
            'id_customer' => Yii::t('common/log', 'Vendég'),
            'id_account' => Yii::t('common/log', 'Kassza'),
            'id_account_state' => Yii::t('common/log', 'Id Account State'),
            'id_key' => Yii::t('common/log', 'Kulcs'),
            'id_product' => Yii::t('common/log', 'Termék'),
            'id_door_log' => Yii::t('common/log', 'Kapu log'),
            'created_at' => Yii::t('common/log', 'Dátum idő'),
            'updated_at' => Yii::t('common/log', 'Módosítás'),
        		'start' => 'Időszak kezdete',
        		'end' => 'Időszak vége'
        ];
    }
    
    
    public static function info($message ){
    	self::log(['type' =>self::$TYPE_INFO, 'message' => $message]);
    }
    
    /**
     * example
     * Log::log([
        			'type' =>Log::$TYPE_LOGIN,
        			'message' => $message
        	]);
     * @param unknown $config
     */
    public static function log( $config ){
    	$model = new Log($config);
    	$model->app = \Yii::$app->name;
    	$model->url = Url::canonical();
    	$model->id_user = \Yii::$app->user->id;
    	$model->save(false);
    }
    
}
