<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class AttendanceSession extends Model {
    protected $fillable=['organization_id','activity_id','title','token','opens_at','closes_at','location_name','latitude','longitude','radius_meters','require_location','require_photo','one_device_one_person','allow_public','is_active','retention_months'];
    protected $casts=['opens_at'=>'datetime','closes_at'=>'datetime','require_location'=>'boolean','require_photo'=>'boolean','one_device_one_person'=>'boolean','allow_public'=>'boolean','is_active'=>'boolean','latitude'=>'decimal:7','longitude'=>'decimal:7'];
    public function organization(){ return $this->belongsTo(Organization::class); }
    public function activity(){ return $this->belongsTo(Activity::class); }
    public function entries(){ return $this->hasMany(AttendanceEntry::class); }
    public function isOpen(): bool { $now=now(); return $this->is_active && (!$this->opens_at || $now->gte($this->opens_at)) && (!$this->closes_at || $now->lte($this->closes_at)); }
}
