<?php

namespace App\Models;

use App\Http\Controllers\Hr\Employees\CompanyEmployeesController;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class EmployeeAdvanceSalary extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    /**An Advance Salary belongs to a Specific employee**/
    public function employee()
    {
        return $this->belongsTo(User::class, 'u_id');
    }

    /**An Advance Salary is Applied/Registered by a specific user **/
    public function user()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    /**An Advance Salary is Reversed by a Single User**/
    public function reversedBy(){
        return $this->belongsTo(User::class, 'reversed_by', 'id');
    }
    /**An Advance Salary is First approved by a Specific User**/
    public function firstApprover(){
        return $this->belongsTo(User::class, 'first_approved_by');
    }

    /**An Advance Salary is Second approved by a Specific User**/
    public function secondApprover(){
        return $this->belongsTo(User::class, 'second_approved_by');
    }

    /**An Advance Entry has many Schedules attached to it **/
    public function advanceSalarySchedules(){
        return $this->hasMany(EmployeeAdvanceSalarySchedule::class, 'advance_id');
    }

    /**An Advance Salary has Some amount Paid/Repaid on it**/
    public function advanceSalaryPaidAmount($id)
    {
        return (new CompanyEmployeesController)->advanceSalaryPaidAmount($id);
    }

    /**An Advance Salary has Some Balance Figure pending to be Cleared**/
    public function advanceSalaryBalance($id)
    {
        return (new CompanyEmployeesController)->advanceSalaryBalance($id);
    }
}
