<?php

namespace App\Models;

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

class EmployeeDeductionType extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    /**This Deduction Type was created by a Specific User**/
    public function user()
    {
        return $this->belongsTo(User::class, 'created_by', 'id');
    }

    /**An Employee Deduction Type has Many calculator Options**/
    public function calculator(){
        return $this->hasMany(EmployeeDeductionCalculator::class, 'deduction_id');
    }

    /**A Deduction Type has a Specific Ledger attached to it**/
    public function expenseLedger()
    {
        return $this->hasOne(CompanyChartsOfAccount::class, 'id','ledger_id');
    }

    /**A Deduction Type has Many Employee Deduction Fields **/
    public function employeeDeductionFields()
    {
        return $this->hasMany(EmployeeDeductionRequiredField::class, 'deduction_id');
    }

    /**Create a Standard Function that will check if a Given Deduction type has a particular Employee Field**/
    public function hasFieldName($id,$name)
    {
        return (new EmployeeDeductionController)->hasFieldName($id, $name);
    }
}
