<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;

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

    protected $table = 'shop_sale_channels';

    public function deliveries()
    {
        return $this->hasMany(Delivery::class);
    }

    public function price_lists()
    {
        return $this->hasMany(PriceList::class);
    }

    public function tariffs()
    {
        return $this->hasManyThrough(Tariff::class, PriceList::class, 'sale_channel_id', 'id', 'id', 'tariff_id');
    }

    public function scopeByCode($query, $code)
    {
        return $query->where($this->table.'.code', $code);
    }
}
