<?php

namespace App\Models;

use App\Classes\General\Interfaces\Addressable;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

use Illuminate\Database\Eloquent\SoftDeletes;
use PhpParser\Node\Expr\AssignOp\Mod;

/**
 * Class CompanyModule
 * @package App\Models
 *
 * @property \App\Models\Company company_id 
 * @property integer type
 * @property integer status
 */
class CompanyConnection extends AbstractModel
{
    use SoftDeletes;

    protected $table = 'company_connections';

    protected $dates = ['deleted_at'];

    /**
     * @return BelongsTo
     */
    public function inviter(): BelongsTo
    {
        return $this->BelongsTo(CompanyModule::class);
    }

    /**
     * @return BelongsTo
     */
    public function invitee(): BelongsTo
    {
        return $this->BelongsTo(CompanyModule::class);
    }

    /**
     * @param Builder $query
     * @return Builder
     */
    public function scopeApproved(Builder $query)
    {
        return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
    }


    /**
     * @return belongsToMany
     */
    public function segments(): belongsToMany
    {
        return $this->belongsToMany(Segment::class, (new ConnectionSegment())->getTable(), 'company_connection_id', 'segment_id');
    }

}
