<?php

namespace App\Models;

use Database\Factories\ApplicationFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Application extends Model
{
    /** @use HasFactory<ApplicationFactory> */
    use HasFactory;

    public const STATUS_SAVED = 'saved';

    public const STATUS_APPLIED = 'applied';

    public const STATUS_INTERVIEW = 'interview';

    public const STATUS_REJECTED = 'rejected';

    public const STATUS_OFFER = 'offer';

    public const STATUS_FOLLOW_UP_NEEDED = 'follow_up_needed';

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'user_id',
        'imported_job_id',
        'job_source_id',
        'source_url',
        'apply_url',
        'source_attribution',
        'status',
        'notes',
        'follow_up_at',
        'ip_address',
        'user_agent',
        'applied_at',
    ];

    /**
     * @return BelongsTo<User, $this>
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * @return BelongsTo<ImportedJob, $this>
     */
    public function importedJob(): BelongsTo
    {
        return $this->belongsTo(ImportedJob::class);
    }

    /**
     * @return BelongsTo<JobSource, $this>
     */
    public function source(): BelongsTo
    {
        return $this->belongsTo(JobSource::class, 'job_source_id');
    }

    /**
     * @return HasMany<ApplicationFollowUpReminder, $this>
     */
    public function reminders(): HasMany
    {
        return $this->hasMany(ApplicationFollowUpReminder::class);
    }

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'follow_up_at' => 'date',
            'applied_at' => 'datetime',
        ];
    }
}
