<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    protected $fillable = [
        'name',
        'email',
        'phone',
        'designation',
        'department',
        'photo',
        'manager_id',
        'base_salary',
        'joined_date',
        'is_on_probation',
        'probation_end_date',
        'sick_leave_limit',
        'casual_leave_limit',
        'bank_name',
        'account_number',
        'ifsc_code',
        'father_name',
        'mother_name',
        'total_experience',
    ];

    protected $appends = ['photo_url'];

    public function getPhotoUrlAttribute()
    {
        return $this->photo ? asset('storage/' . $this->photo) : asset('img/default-avatar.png');
    }

    public function manager()
    {
        return $this->belongsTo(Employee::class, 'manager_id');
    }

    public function subordinates()
    {
        return $this->hasMany(Employee::class, 'manager_id');
    }

    public function attendances()
    {
        return $this->hasMany(Attendance::class);
    }

    public function salaries()
    {
        return $this->hasMany(Salary::class);
    }

    public function attendanceRequests()
    {
        return $this->hasMany(AttendanceRequest::class);
    }

    public function leaveRequests()
    {
        return $this->hasMany(LeaveRequest::class);
    }

    public function user()
    {
        return $this->hasOne(User::class);
    }

    public function deductions()
    {
        return $this->hasMany(EmployeeDeduction::class);
    }

    public function additions()
    {
        return $this->hasMany(EmployeeAddition::class);
    }


    public function documents()
    {
        return $this->hasMany(EmployeeDocument::class);
    }

    public function profileUpdateRequests()
    {
        return $this->hasMany(ProfileUpdateRequest::class);
    }

    public function assets()
    {
        return $this->hasMany(Asset::class, 'assigned_to');
    }
}
