<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;

class Package extends Model
{
    protected $guarded = ['id'];

    protected $table = 'shop_packages';

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

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

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

    public function offers(): HasManyThrough
    {
        return $this->hasManyThrough(Offer::class, Variation::class);
    }

    public function scopeByArticleNature($query, $id)
    {
        return $query->where($this->table.'.article_family_id', $id);
    }
}
