<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Training extends Model
{
    protected $fillable = [
        'title','description','type','facilitator','provider',
        'location','start_date','end_date','cost','max_participants',
        'status','certificate_template','created_by',
    ];

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

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

    public function participants()
    {
        return $this->belongsToMany(Employee::class, 'training_participants')
                    ->withPivot('status','score','certificate_issued','certificate_date')
                    ->withTimestamps();
    }
}
