<?php

namespace App\Models;

use Database\Factories\ProfileFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Profile extends Model
{
    /** @use HasFactory<ProfileFactory> */
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'user_id',
        'headline',
        'summary',
        'current_role',
        'experience_level',
        'country_code',
        'city',
        'timezone',
        'skills',
        'preferred_roles',
        'preferred_categories',
        'links',
        'availability',
        'salary_currency',
        'salary_min',
        'open_to_contract',
        'open_to_full_time',
        'completed_at',
    ];

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

    public function isCompleted(): bool
    {
        return $this->completed_at !== null;
    }

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'skills' => 'array',
            'preferred_roles' => 'array',
            'preferred_categories' => 'array',
            'links' => 'array',
            'salary_min' => 'integer',
            'open_to_contract' => 'boolean',
            'open_to_full_time' => 'boolean',
            'completed_at' => 'datetime',
        ];
    }
}
