<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Announcement extends Model
{
    protected $fillable = [
        'title',
        'content',
        'type',
        'is_popup',
        'is_active',
        'order',
    ];

    protected $casts = [
        'is_popup' => 'boolean',
        'is_active' => 'boolean',
        'order' => 'integer',
    ];

    /**
     * Scope for active announcements only
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Scope for popup announcements only
     */
    public function scopePopup($query)
    {
        return $query->where('is_popup', true);
    }

    /**
     * Get CSS class based on type
     */
    public function getAlertClassAttribute()
    {
        $classes = [
            'info' => 'alert-info',
            'warning' => 'alert-warning',
            'success' => 'alert-success',
            'danger' => 'alert-danger',
        ];

        return $classes[$this->type] ?? 'alert-info';
    }

    /**
     * Get icon based on type
     */
    public function getIconAttribute()
    {
        $icons = [
            'info' => 'bi-info-circle',
            'warning' => 'bi-exclamation-triangle',
            'success' => 'bi-check-circle',
            'danger' => 'bi-x-circle',
        ];

        return $icons[$this->type] ?? 'bi-info-circle';
    }
}
