<?php

namespace App\Models;

class AddressBook extends AbstractModel
{
    protected $table = 'address_book';

    protected $fillable = [
        'type', 'reference_id', 'reference', 'contact', 'street_one', 'street_two', 'city', 'state', 'post_code', 'country', 'default', 'billing'
    ];

    public function forwarder()
    {
        return $this->belongsTo('App\Models\Forwarder', 'id', 'reference_id')->where('type', '=', 0);
    }

    public function company()
    {
        return $this->belongsTo('App\Models\Company', 'id', 'reference_id')->where('type', '=', 1);
    }

    public function warehouse()
    {
        return $this->belongsTo('App\Models\Warehouse', 'id', 'reference_id')->where('type', '=', 2);
    }
}
