<?php

namespace App\Models\Shop;

use App\Traits\Model\HasComments;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Variation extends Model
{
    use HasComments;

    protected $guarded = ['id'];

    protected $table = 'shop_variations';

    public function package(): BelongsTo
    {
        return $this->belongsTo(Package::class);
    }

    public function unity(): BelongsTo
    {
        return $this->belongsTo(Unity::class);
    }

    public function offers(): HasMany
    {
        return $this->hasMany(Offer::class);
    }

    public function scopeByPackage($query, $packageId)
    {
        return $query->where($this->table . '.package_id', $packageId);
    }

    public function scopeByUnity($query, $unityId)
    {
        return $query->where($this->table . '.unity_id', $unityId);
    }
}
