<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Branch extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'code',
        'name_en',
        'name_ar',
        'vat_number_override',
        'cr_number',
        'phone',
        'email',
        'building_number',
        'street_name',
        'district',
        'city',
        'postal_code',
        'additional_number',
        'manager_name',
        'invoice_prefix',
        'default_warehouse_id',
        'status',
    ];

    public function warehouses()
    {
        return $this->hasMany(Warehouse::class);
    }

    public function defaultWarehouse()
    {
        return $this->belongsTo(Warehouse::class, 'default_warehouse_id');
    }

    public function users()
    {
        return $this->belongsToMany(User::class, 'user_branches');
    }
}
