<?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;
use Illuminate\Database\Eloquent\SoftDeletes;

class RecruitmentInterview extends Model
{
    use BelongsToTenant;
    use SoftDeletes;

    protected $table = 'recruitment_interviews';

    protected $fillable = [
        'tenant_id',
        'reference_code',
        'application_id',
        'scheduled_at',
        'mode',
        'location',
        'interviewer_user_id',
        'status',
        'notes',
        'created_by',
    ];

    protected function casts(): array
    {
        return [
            'scheduled_at' => 'datetime',
        ];
    }

    public function application(): BelongsTo
    {
        return $this->belongsTo(RecruitmentApplication::class, 'application_id');
    }

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

    public function scorecards(): HasMany
    {
        return $this->hasMany(RecruitmentInterviewScorecard::class, 'interview_id');
    }

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