<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'designation',
        'phone',
        'email',
        'salary_type',
        'salary_amount',
        'advance_amount',
        'hired_at',
        'joining_date',
        'resign_date',
        'status',
        'notes',
    ];

    protected $casts = [
        'hired_at'     => 'date',
        'joining_date' => 'date',
        'resign_date'  => 'date',
    ];

    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }

    public function payments()
    {
        return $this->hasMany(EmployeePayment::class);
    }

    public function rosters()
    {
        return $this->hasMany(Roster::class);
    }

    public function salaryHistories()
    {
        return $this->hasMany(EmployeeSalaryHistory::class)->orderByDesc('effective_date');
    }
}
