<?php

namespace App\Models;

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

class Employee extends Model
{
    use HasFactory;

    protected $fillable = [
        'job_title_id',
        'name',
        'job_title',
        'basic_salary',
        'commission_rate',
        'status',
        'phone',
        'email',
        'profile_image',
        'documents',
        'join_date',
    ];

    protected $casts = [
        'basic_salary' => 'decimal:2',
        'commission_rate' => 'decimal:2',
        'join_date' => 'date',
        'documents' => 'array',
    ];

    public function jobTitle()
    {
        return $this->belongsTo(JobTitle::class);
    }

    public function branches()
    {
        return $this->belongsToMany(Branch::class);
    }

    public function branch()
    {
        return $this->belongsTo(Branch::class);
    }

    public function payrolls()
    {
        return $this->hasMany(Payroll::class);
    }
}
