<?php

namespace App\Models\ProductManagement;

use App\Models\Traits\Activable;
use App\Models\Traits\Bootables\Auditable;
use App\Models\UserManagement\Customer;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Nicolaslopezj\Searchable\SearchableTrait;

class Review extends Model{
    use HasFactory, SearchableTrait,Activable,Auditable;

    protected $guarded = [];
    protected $table = "product_mgt__reviews";


    protected $searchable = [
        'columns' => [
            'reviews.content' => 10,
            'users.first_name' => 10,
            'users.email' => 10,
        ],
        'joins' => [
            'users' => ['users.id', 'reviews.user_id'],
        ]
    ];

    public function getStatusAttribute(): string{
        return $this->attributes['active'] == 0 ? 'Inactive' : 'Active';
    }

    public function product(): BelongsTo{
        return $this->belongsTo(Product::class,"product_id");
    }

    public function user(): BelongsTo{
        return $this->belongsTo(Customer::class,"customer_id");
    }
}
