<?php

namespace App\Modules\HR\Recruitment\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 RecruitmentOnboardingTask extends Model
{
    use BelongsToTenant;

    protected $table = 'recruitment_onboarding_tasks';

    protected $fillable = [
        'tenant_id',
        'onboarding_case_id',
        'section',
        'title',
        'description',
        'status',
        'is_required',
        'assigned_to',
        'due_date',
        'completed_at',
        'completed_by',
        'notes',
        'sort_order',
        'meta',
    ];

    protected function casts(): array
    {
        return [
            'is_required' => 'boolean',
            'due_date' => 'date',
            'completed_at' => 'datetime',
            'meta' => 'array',
            'sort_order' => 'integer',
        ];
    }

    public function onboardingCase(): BelongsTo
    {
        return $this->belongsTo(RecruitmentOnboardingCase::class, 'onboarding_case_id');
    }

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

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

    public function attachments(): HasMany
    {
        return $this->hasMany(RecruitmentOnboardingAttachment::class, 'onboarding_task_id');
    }
}
