<?php

namespace App\Models;

use App\Core\Traits\SpatieLogsActivity;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail
{
    use HasFactory;
    use Notifiable;
    use SpatieLogsActivity;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'username',
        'password',
        'email',
        'role_id',
        'avatar',
        'coverpic',
        'bio',
        'status',
        'api_token',
        'stripe_id',
        'profile_views',
        'list_views',
        'blog_views',
        'banned',
        'user_deleted',
        'ip_address'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'api_token',
        'stripe_id',
        'remember_token'
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function getRememberToken()
    {
        return $this->remember_token;
    }

    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    /**
     * User relation to user gamertags model
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function gamertags()
    {
        return $this->hasOne(UserGamerTag::class);
    }

    /**
     * User relation to user info model
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function info()
    {
        return $this->hasOne(UserInfo::class);
    }

    /**
     * User relation to user notification settings model
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function notifications()
    {
        return $this->hasOne(UserNotificationSetting::class);
    }

    /**
     * User relation to role model
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function role()
    {
        return $this->hasOne(Role::class, 'id', 'role_id');
    }

    /**
     * User relation to game list model
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function gameList()
    {
        return $this->hasMany(GameList::class);
    }

    /**
     * User relation to user site settings model
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function siteSettings()
    {
        return $this->hasMany(UserSiteSetting::class);
    }
}
