<?php

namespace Modules\Rate\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Product\Models\Product;
use Modules\User\Enums\AccountStatusEnum;
use Modules\User\Models\User;
use Modules\User\Models\Visitor;

class Rate extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'rate','comment','comment','user_id','status','product_id'
    ];


    /**
     * Get current description of the the Room
     * @return HasOne
     */
    public function user() :BelongsTo
    {
        $user = $this->status == AccountStatusEnum::VISITOR->value ?
            $this->belongsTo(Visitor::class,'user_id')->withTrashed() :
            $this->belongsTo(User::class,'user_id')->withTrashed();
        return $user;
    }
    public function visitor ()
    {
        return $this->belongsTo(Visitor::class,'user_id')->withTrashed();
    }
    public function product()
    {
        return $this->belongsTo(Product::class,'product_id')->withTrashed();
    }

}
