<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;

class Employee extends Model
{
    use HasFactory;

    protected $table = 'employees';
    protected $fillable = [
        'organization_id',
        'employee_name',
        'father_name',
        'mother_name',
        'birth_date',
        'sex',
        'present_address',
        'permanent_address',
        'email',
        'mobile_no',
        'nid_no',
        'branch_id',
        'designation_id',
        'department_id',
        'joining_date',
        'employee_image',
        'added_by',
        'added_on',
        'updated_at',
        'updated_by'
    ];

    public function organization() {
        return $this->belongsTo(Organization::class,'organization_id');
    }

    public function alerts() {
        return $this->hasMany(Alert::class,'employee_id');
    }
    /** @return HasMany */
    public function employee_images(): HasMany {
        return $this->hasMany(EmployeeImage::class);
    }

    public function user() {
        return $this->belongsTo(User::class,'created_by');
    }

    /////////////////
    // public function employees_records(): HasManyThrough {
    //     return $this->hasManyThrough(Employees_record::class, Designation::class);
    // }
    public function employeeRecords() {//its OK
        return $this->hasMany(EmployeeRecord::class);
    }
    public function designation() {
        return $this->belongsTo(Designation::class);
    }
    public function department() {
        return $this->belongsTo(Department::class);
    }
}
