<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Banner extends Model
{
    protected $fillable = [
        'name', 'type', 'content', 'link_url', 'link_text',
        'position', 'background_color', 'text_color', 'image',
        'starts_at', 'ends_at', 'is_active', 'order',
    ];

    protected $casts = [
        'starts_at' => 'date',
        'ends_at' => 'date',
        'is_active' => 'boolean',
    ];

    public const TYPE_BAR = 'bar';
    public const TYPE_POPUP = 'popup';
    public const TYPE_ALERT = 'alert';

    public const POSITION_TOP = 'top';
    public const POSITION_BOTTOM = 'bottom';
    public const POSITION_FLOATING = 'floating';

    public function isCurrentlyActive(): bool
    {
        if (! $this->is_active) {
            return false;
        }
        $now = now()->startOfDay();
        if ($this->starts_at && $this->starts_at->gt($now)) {
            return false;
        }
        if ($this->ends_at && $this->ends_at->lt($now)) {
            return false;
        }
        return true;
    }
}
