<?php

namespace App\Models;

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

class Application extends Model
{
    protected $fillable = [
        'job_post_id',
        'researcher_id',
        'first_name',
        'last_name',
        'email',
        'phone',
        'resume_path',
        'resume_url',
        'cover_letter',
        'experience_level',
        'available_date',
        'notice_period',
        'salary_expectation',
        'remote_interested',
        'additional_answers',
        'consent_data',
        'consent_marketing',
        'interview_link',
        'feedback',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'remote_interested' => 'boolean',
            'consent_data' => 'boolean',
            'consent_marketing' => 'boolean',
            'additional_answers' => 'array',
            'available_date' => 'date',
            'salary_expectation' => 'integer',
        ];
    }

    /**
     * Get the job post that the application belongs to.
     */
    public function jobPost(): BelongsTo
    {
        return $this->belongsTo(JobPost::class);
    }

    /**
     * Get the researcher/applicant.
     */
    public function researcher(): BelongsTo
    {
        return $this->belongsTo(User::class, 'researcher_id');
    }

    /**
     * Get the interviews for this application.
     */
    public function interviews(): HasMany
    {
        return $this->hasMany(Interview::class);
    }
}
