<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class PopupAnnouncement extends Model {
    protected $fillable=['organization_id','title','body','image_path','button_label','button_url','frequency','starts_at','ends_at','show_desktop','show_mobile','is_active','sort_order'];
    protected $casts=['starts_at'=>'datetime','ends_at'=>'datetime','show_desktop'=>'boolean','show_mobile'=>'boolean','is_active'=>'boolean'];
    public function organization(){ return $this->belongsTo(Organization::class); }
    public function scopeCurrentlyActive($q){ return $q->where('is_active',true)->where(fn($x)=>$x->whereNull('starts_at')->orWhere('starts_at','<=',now()))->where(fn($x)=>$x->whereNull('ends_at')->orWhere('ends_at','>=',now())); }
}
