<?php

namespace App\Models;

use App\Classes\General\Interfaces\Documentable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;


/**
 * Class Company
 * @package App\Models
 * @version August 4, 2020, 4:21 am
 *
 * @property string name
 * @property integer type
 */
class Company extends AbstractModel implements Documentable
{

    use SoftDeletes;


    protected $table = 'companies';
    
    protected $dates = ['deleted_at'];

    /**
     * @return HasMany
     */
    public function addresses(): hasMany
    {
        return $this->hasMany(Address::class, 'company_id', 'id');
    }

    /**
     * @return HasMany
     */
    public function contacts(): hasMany
    {
        return $this->hasMany(Contact::class, 'company_id', 'id');
    }

    /**
     * @return HasOne
     */
    public function deliveryAddress(): hasOne {
        return $this->hasOne(Address::class)->where('default', 1);
    }

    /**
     * @return HasMany
     */
    public function modules(): hasMany
    {
        return $this->hasMany(CompanyModule::class);
    }


    /**
     * @return HasManyThrough
     */
    public function connections(): hasManyThrough
    {
        return $this->hasManyThrough(Company::class, CompanyConnections::class);
    }

    /**
     * @return MorphMany
     */
    public function documents(): morphMany
    {
        return $this->morphMany(Document::class, 'owner');
    }

    /**
     * @return HasMany
     */
    public function orders(): hasMany
    {
        return $this->hasMany(Order::class);
    }

    

}
