<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Venturecraft\Revisionable\RevisionableTrait;
use Wildside\Userstamps\Userstamps;

class DeliveryTypeCalculation extends Model
{
    use RevisionableTrait, SoftDeletes, Userstamps;

    protected $guarded = ['id'];

    protected $table = 'shop_delivery_type_calculations';

    protected $revisionEnabled = true;

    protected $keepRevisionOf = ['type_id', 'weight', 'price'];

    public function delivery_type(): BelongsTo
    {
        return $this->belongsTo(DeliveryType::class, 'type_id');
    }

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

    public function scopeByWeight($query, $weight)
    {
        return $query->orderBy('weight')->where($this->table.'.weight', '>=', $weight);
    }
}
