<?php

namespace App\Models;

use App\Models\AbstractModel as Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;


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

    use SoftDeletes;

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


    public $fillable = [
        'module_type'
    ];

    /**
     * @return BelongsTo
     */
    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }

    /**
     * @return belongsToMany
     */
    public function employees(): belongsToMany
    {
        return $this->belongsToMany(User::class, (new CompanyEmployee())->getTable(), 'module_id','user_id');
    }

    /**
     * @return BelongsToMany
     */
    public function connections(): belongsToMany
    {
        return $this->belongsToMany(CompanyModule::class, (new CompanyConnections())->getTable(), 'module_one', 'module_two');
    }

}
