<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "utente".
 *
 * @property string $msisdn
 * @property string $cognome
 * @property string $nome
 * @property string $email
 * @property string $data_nascita
 * @property string $data_registrazione
 * @property string $data_ultimo_login
 * @property string $cognome_2
 * @property string $nome_2
 * @property string $data_scadenza_nominativo
 * 
 */
class Utente extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'utente';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['msisdn', 'data_registrazione', 'data_ultimo_login'], 'required'],
            [['data_registrazione', 'data_ultimo_login', 'cognome_2', 'nome_2', 'data_scadenza_nominativo'], 'safe'],
            [['msisdn', 'data_nascita'], 'string', 'max' => 16],
            [['cognome', 'nome', 'email'], 'string', 'max' => 128]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'msisdn' => 'Msisdn',
            'cognome' => 'Cognome',
            'nome' => 'Nome',
            'email' => 'Email',
            'data_nascita' => 'Data Nascita',
            'data_registrazione' => 'Data Registrazione',
            'data_ultimo_login' => 'Data Ultimo Login',
        ];
    }

    /**
     * @inheritdoc
     */
    public static function findIdentity($id) {
        return static::findOne(['msisdn' => $id]);
    }

    /**
     * @inheritdoc
     */
    public static function findIdentityByAccessToken($token, $type = null) {
        throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
    }

    /**
     * Finds user by username
     *
     * @param string $username
     * @return static|null
     */
    public static function findByUsername($username) {
        return static::findOne(['msisdn' => $username]);
    }

    /**
     * @inheritdoc
     */
    public function getId() {
        return $this->msisdn;
    }

    public function getNome() {
        return $this->nome;
    }

    /**
     * @inheritdoc
     */
    public function getAuthKey() {
        return $this->auth_key;
    }

    /**
     * @inheritdoc
     */
    public function validateAuthKey($authKey) {
        return $this->getAuthKey() === $authKey;
    }

}
