<?php

namespace Modules\HR\Models\Traits;

use Modules\HR\Models\SalaryStructureItem;


trait SalaryStructureRelationshipTrait
{
    public function basicSalaryAmount(): float
    {
        return (float) $this->items()
            ->where('is_basic', true)
            ->value('calculation_value') ?? 0;
    }

    public function items()
    {
        return $this->hasMany(SalaryStructureItem::class);
    }

    public function basicItem()
    {
        return $this->hasOne(SalaryStructureItem::class)
            ->where('is_basic', true);
    }
}
