<?php

namespace common\models;

use Yii;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "user_log".
 *
 * @property int $id
 * @property string $log_type
 * @property string $description
 * @property int $ref_id
 * @property string $table_name
 * @property int|null $created_by
 * @property int|null $created_at
 * @property int|null $updated_by
 * @property int|null $updated_at
 */
class UserLog extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'user_log';
    }
    public function behaviors()
    {
        return [
            TimestampBehavior::class,
            BlameableBehavior::class,
        ];
    }
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['log_type', 'description', 'ref_id', 'table_name'], 'required'],
            [['description', 'table_name', 'ip'], 'string'],
            [['ref_id', 'created_by', 'created_at', 'updated_by', 'updated_at'], 'integer'],
            [['log_type'], 'string', 'max' => 100],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'log_type' => 'Log Type',
            'description' => 'Description',
            'ref_id' => 'Ref ID',
            'table_name' => 'Table Name',
            'ip' => 'IP',
            'created_by' => 'ผู้แก้ไข',
            'created_at' => 'วันที่เวลาเก็บ (Log)',
            'updated_by' => 'Updated By',
            'updated_at' => 'Updated At',
        ];
    }

    public function getCreatedBy()
    {
        return $this->hasOne(User::class, ['id' => 'created_by']);
    }

    public function getUpdateBy()
    {
        return $this->hasOne(User::class, ['id' => 'updated_by']);
    }
}