<?php

namespace App\Modules\HR\Core\Models;

use App\Modules\HR\Payroll\Models\Addition;
use App\Modules\HR\Payroll\Models\Deduction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use App\Modules\PLATFORM\Settings\Models\Branch;
use App\Modules\PLATFORM\Settings\Models\BranchScoped;

class Designation extends Model
{
    use HasFactory;
    use BranchScoped;
    protected $table = 'designations';

    protected $fillable = [
        'branch_id',
        'code',
        'name',
        'level',
        'budget',
        'carder',
        'is_managerial',
        'status',
    ];

    protected $casts = [
        'level' => 'integer',
        'is_managerial' => 'boolean',
        'status' => 'boolean',
    ];

    /* ================= Relationships ================= */

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

    public function additions(): BelongsToMany
    {
        return $this->belongsToMany(Addition::class, 'designation_additions')
            ->withTimestamps();
    }

    public function deductions(): BelongsToMany
    {
        return $this->belongsToMany(Deduction::class, 'designation_deductions')
            ->withTimestamps();
    }
}
