<?php

namespace App\Models;

use App\Enums\IsPaid;
use Dyrynda\Database\Support\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Veelasky\LaravelHashId\Eloquent\HashableId;

class Payroll extends Model
{
    use CascadeSoftDeletes, HasFactory, HashableId, SoftDeletes;

    protected $guarded = ['id'];

    protected $cascadeDeletes = ['adjustments'];

    protected function casts(): array
    {
        return [
            'base_salary' => 'int',
            'bonus' => 'int',
            'deduction' => 'int',
            'total_salary' => 'int',
            'is_paid' => IsPaid::class,
        ];
    }

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

    public function adjustments(): HasMany
    {
        return $this->hasMany(PayrollAdjustment::class);
    }
}
