<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Employee extends BaseModel {
    use SoftDeletes;
    protected function casts(): array { return ['date_of_birth' => 'date', 'date_employed' => 'date', 'date_confirmed' => 'date', 'date_exited' => 'date', 'allowances' => 'array']; }
    public function department() { return $this->belongsTo(Department::class); }
    public function designation() { return $this->belongsTo(Designation::class); }
    public function user() { return $this->belongsTo(User::class); }
    public function quarry() { return $this->belongsTo(Quarry::class); }
    public function getFullNameAttribute(): string { return trim($this->first_name.' '.$this->last_name); }
    public function getDisplayNameAttribute(): string { return $this->employee_no.' – '.$this->full_name; }
    public function allowancesTotal(): float { return (float) collect($this->allowances ?? [])->sum(); }
}
