<?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\Order\Models\Order;
use Modules\Product\Models\Product;
use Modules\Rate\Enums\RateStatusEnum;
use Modules\Store\Models\Store;
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','user_id','status','order_id'
    ];


    public function getDateAttribute()
    {
        $date = date('d',strtotime($this->created_at));
        $date .= ' '.__('web.monthes.'.date('m',strtotime($this->created_at)));
        $date .= ' '.date('Y',strtotime($this->created_at));
        return $date;
    }
    /**
     * Get current description of the the Room
     * @return HasOne
     */
    public function account() :BelongsTo
    {
        $user = $this->status == RateStatusEnum::USER->value ?
            $this->belongsTo(User::class,'user_id')->withTrashed() :
            $this->belongsTo(Store::class,'user_id')->withTrashed();
        return $user;
    }
    public function store ()
    {
        return $this->belongsTo(Store::class,'user_id')->withTrashed();
    }
    public function user ()
    {
        return $this->belongsTo(User::class,'user_id')->withTrashed();
    }
    public function order()
    {
        return $this->belongsTo(Order::class,'order_id')->withTrashed();
    }

}
