<?php

namespace Modules\User\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Modules\Product\Models\Favorite;
use Modules\Type\Models\Type;
use Modules\User\Services\AccountService;

class Visitor extends Model
{
    protected $fillable = ['token','language','device_token', 'type_id', 'address_id'];

    private AccountService $accountService;
    public function __construct(array $attributes = [] )
    {
        parent::__construct($attributes);
        $this->accountService = app(AccountService::class);
    }
    public function address()
    {
        return $this->belongsTo(Address::class)->withTrashed();
    }
    public function type()
    {
        return $this->belongsTo(Type::class)->withTrashed();
    }

    public function favorited($product_id)
    {
        $account = $this->accountService->getAccount();
        $favorite = $this->hasOne(Favorite::class,'user_id')->where('user_status',$account['status'])->where('user_id',$this->id)->where('product_id',$product_id)->first();
        return $favorite;
    }
}
