<?php

namespace RuLong\Identity\Events;

use App\User;
use RuLong\Identity\Contracts\IdentityContracts;
use RuLong\Identity\Models\IdentityPoint as IdentityPointModel;
use RuLong\Identity\Traits\Identityable;

class IdentityPoint implements IdentityContracts
{
    use Identityable;

    public $user;
    public $identity_id;
    public $point;

    public function __construct($user, array $other = null)
    {
        $this->user        = User::find($user->id);
        $this->identity_id = $other['identity_id'];
        if (isset($other['point']) && is_numeric($other['point'])) {
            $this->point = $other['point'];
        } else {
            $this->point = 1;
        }
    }

    /**
     * 创建及修改身份
     * @Author:<Leady>
     * @Date:2018-11-05T13:21:47+0800
     * @return [type] [description]
     */
    public function fire()
    {
        if ($this->user->id === 1) {
            return false;
        }
        IdentityPointModel::create([
            'user_id'     => $this->user->id,
            'identity_id' => $this->identity_id,
            'point'       => $this->point,
        ]);
    }

}
