<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class EvaluationForm extends Model
{
    protected $fillable = [
        'created_by', 'title', 'description', 'start_date', 
        'end_date', 'target_role', 'status'
    ];

    protected $casts = [
        'start_date' => 'date',
        'end_date' => 'date',
    ];

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

    public function questions()
    {
        return $this->hasMany(FormQuestion::class, 'form_id')->orderBy('order');
    }

    public function responses()
    {
        return $this->hasMany(FormResponse::class, 'form_id');
    }

    public function scopeActive($query)
    {
        return $query->where('status', 'published')
                    ->where('start_date', '<=', now())
                    ->where('end_date', '>=', now());
    }

    public function scopePublished($query)
    {
        return $query->where('status', 'published');
    }
}
