<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Marketplace extends Model
{
    protected $fillable = [
        'name', 'country', 'warehouse', 'seller', 'shipping_type',
        'seller_center', 'user_id', 'status'
    ];
    // un marketplace puede tener varios proveedores
    public function brands()
    {
        return $this->hasMany(MkpVendor::class, 'mkp_id');
    }
    public function seller_data()
    {
        return $this->belongsTo(SellerCenter::class, 'seller_center');
    }

    function scopePortal($query, $portal = null)
    {

        if ($portal) {
            return $query->where('seller', $portal);
        }
    }
    function scopeMarketplace($query, $mkp = null)
    {

        if ($mkp) {
            return $query->where('seller_center', $mkp);
        }
    }
    function scopeCountry($query, $country = null)
    {

        if ($country) {
            return $query->where('country', $country);
        }
    }
    function scopeWarehouse($query, $warehouse = null)
    {

        if ($warehouse) {
            return $query->where('warehouse', $warehouse);
        }
    }
}
