<?php

namespace Yas\Member\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
use Laravel\Sanctum\HasApiTokens;
use Shetabit\Visitor\Traits\Visitor;
use Yas\Member\Contracts\Member as MemberContract;
use Illuminate\Database\Eloquent\Model;
use Yas\Member\Mail\ResetPasswordNotification;

class Member extends Authenticatable implements MemberContract
{

    use HasApiTokens, HasFactory, Notifiable, Visitor;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'member';

    protected $fillable = [
        'first_name',
        'last_name',
        'gender',
        'date_of_birth',
        'email',
        'phone',
        'password',
        'api_token',
        'token',
        'yas_role_id',
        'channel_id',
        'subscribed_to_news_letter',
        'status',
        'is_verified',
        'is_suspended',
    ];

    protected $hidden = [
        'password',
        'api_token',
    ];

    protected $appends = ['image_url'];

    /**
     * Get image url for the customer profile.
     *
     * @return string|null
     */
    public function getImageUrlAttribute()
    {
        return $this->image_url();
    }

    public function image_url()
    {
        if (! $this->image) {
            return;
        }

        return Storage::url($this->image);
    }
    /**
     * Send the password reset notification.
     *
     * @param  string  $token
     */
    public function sendPasswordResetNotification($token): void
    {
       
        $this->notify(new ResetPasswordNotification($token));
    }

}
