<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Candidate extends Model
{
    use HasFactory;

    protected $fillable = [
        'code',
        'name',
        'country',
        'source',
        'sponsorship',
        'age',
        'age_band',
        'religion',
        'languages',
        'marital_status',
        'children',
        'experience_years',
        'experience_band',
        'countries_worked',
        'salary',
        'image',
        'video',
        'cv',
        'is_active',
    ];

    protected $casts = [
        'languages' => 'array',
        'countries_worked' => 'array',
        'is_active' => 'boolean',
    ];

    public const AGE_BANDS = [
        '18-25',
        '26-30',
        '31-35',
        '36-45',
        '46+',
    ];

    public static function computeAgeBand(?int $age): ?string
    {
        if (!$age) {
            return null;
        }

        if ($age >= 18 && $age <= 25) {
            return '18-25';
        }

        if ($age >= 26 && $age <= 30) {
            return '26-30';
        }

        if ($age >= 31 && $age <= 35) {
            return '31-35';
        }

        if ($age >= 36 && $age <= 45) {
            return '36-45';
        }

        if ($age >= 46) {
            return '46+';
        }

        return null;
    }
}

