<?php

namespace App\Models;

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

class Interview extends Model
{
    use HasFactory;

    protected $fillable = [
        'job_application_id',
        'job_posting_id',
        'interviewer_id',
        'candidate_name',
        'candidate_email',
        'title',
        'scheduled_at',
        'duration_minutes',
        'location',
        'meeting_link',
        'notes',
        'status',
        'google_event_id',
        'google_calendar_id',
    ];

    protected $casts = [
        'scheduled_at'     => 'datetime',
        'duration_minutes' => 'integer',
    ];

    public function application()
    {
        return $this->belongsTo(JobApplication::class, 'job_application_id');
    }

    public function jobPosting()
    {
        return $this->belongsTo(JobPosting::class);
    }

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

    public function getStatusLabelAttribute(): string
    {
        return match ($this->status) {
            'scheduled'   => 'Planlandı',
            'completed'   => 'Tamamlandı',
            'cancelled'   => 'İptal Edildi',
            'rescheduled' => 'Yeniden Planlandı',
            default       => $this->status ?? 'Bilinmiyor',
        };
    }

    public function getStatusColorAttribute(): string
    {
        return match ($this->status) {
            'scheduled'   => 'blue',
            'completed'   => 'green',
            'cancelled'   => 'red',
            'rescheduled' => 'yellow',
            default       => 'gray',
        };
    }
}