<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class EmployeeCompensation extends Model
{
    protected $table = 'employee_compensations';

    protected $fillable = [
        'business_id', 'user_id', 'basic_salary', 'allowances', 'bonus', 'commission', 'overtime',
        'deductions', 'advances', 'other_deductions', 'effective_from', 'status', 'notes', 'created_by', 'updated_by',
    ];

    protected function casts(): array
    {
        return [
            'basic_salary' => 'decimal:2', 'allowances' => 'decimal:2', 'bonus' => 'decimal:2',
            'commission' => 'decimal:2', 'overtime' => 'decimal:2', 'deductions' => 'decimal:2',
            'advances' => 'decimal:2', 'other_deductions' => 'decimal:2', 'effective_from' => 'date',
        ];
    }

    public function business(): BelongsTo { return $this->belongsTo(Business::class); }
    public function employee(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); }
    public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); }
    public function updater(): BelongsTo { return $this->belongsTo(User::class, 'updated_by'); }
}
