<?php

namespace App\Models\Hrm\Appoinment;

use App\Models\User;
use App\Models\Visit\VisitImage;
use App\Models\coreApp\BaseModel;
use App\Models\Traits\BranchTrait;
use App\Models\Traits\CompanyTrait;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Models\Hrm\Appoinment\AppoinmentParticipant;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Models\coreApp\Traits\Relationship\StatusRelationTrait;

class Appoinment extends BaseModel
{
    use HasFactory,CompanyTrait, StatusRelationTrait,BranchTrait;

    public function visitImages()
    {
        return $this->morphMany(VisitImage::class, 'imageable');
    }
    public function createdBy():BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
    public function appoinmentWith():BelongsTo
    {
        return $this->belongsTo(User::class, 'appoinment_with');
    }
    public function participants():HasMany
    {
        return $this->hasMany(AppoinmentParticipant::class);
    }
    public function otherParticipant()
    {
        return $this->belongsTo(AppoinmentParticipant::class,'appoinment_with','participant_id');
    }

    public static function boot() {
        parent::boot();

        static::deleting(function($appoinment) { 
             $appoinment->participants()->delete();
        });
    }
}
