<?php

namespace App\Modules\HR\Shifts\Models;

use App\Models\User;
use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Shift extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'name',
        'start_time',
        'end_time',
        'grace_minutes',
        'late_after_minutes',
        'overtime_after_minutes',
        'break_minutes',
        'working_days',
        'is_night_shift',
        'is_active',
        'created_by',
        'updated_by',
    ];

    protected function casts(): array
    {
        return [
            'working_days' => 'array',
            'is_night_shift' => 'boolean',
            'is_active' => 'boolean',
            'grace_minutes' => 'integer',
            'late_after_minutes' => 'integer',
            'overtime_after_minutes' => 'integer',
            'break_minutes' => 'integer',
        ];
    }

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

    public function createdByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updatedByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
