<?php

namespace Packages\Product\Models;
use App\Models\Category;
use App\Models\Upload;
use Illuminate\Database\Eloquent\Model;
use App\User;
use Illuminate\Database\Eloquent\SoftDeletes;


class Product extends Model
{
    use SoftDeletes;

//    protected $fillable = ['title', 'discription', 'price', 'creator_id', 'type', 'status', 'sale_price', 'sku', 'slug', 'photo'];
    protected $guarded = [];

    public function user()
    {
        return $this->belongsTo(User::class, 'creator_id', 'id');
    }


    public function categories()
    {
        return $this->morphToMany(Category::class, 'categorizable');
    }
    public function uploads()
    {
        return $this->morphMany(Upload::class, 'uploadable');
    }
    public function getTypeAttribute($value)
    {

        switch ($value) {
            case 0:
                $type = 'ساده';
                break;
            case 1:
                $type = 'متغیر';
                break;
            case 2:
                $type = 'باندل';
                break;

            default:
                $type = '';

        }
        return $type;
    }

    public function getStatusAttribute($value)
    {

        switch ($value) {
            case 0:
                $type = 'ناموجود';
                break;
            case 1:
                $type = 'موجود';
                break;

            default:
                $type = '';

        }
        return $type;
    }
}
