<?php
declare(strict_types=1);

namespace App\Modules\Pricing\Models;

use App\Core\Model;
use App\Core\App;

class DiscountRule extends Model
{
    protected static string $table = 'discount_rules';
    protected static bool $softDelete = false;
    protected static bool $timestamps = true;
    protected static array $fillable = [
        'discount_code', 'name_ar', 'name_en', 'discount_type', 'value',
        'min_quantity', 'max_quantity', 'stackable', 'max_discount_percentage',
        'branch_id', 'effective_from', 'effective_to', 'is_active',
    ];

    public static function allActive(): array
    {
        $db = App::getInstance()->db();
        return $db->select("SELECT * FROM discount_rules WHERE is_active = 1 AND effective_from <= CURDATE() AND (effective_to IS NULL OR effective_to >= CURDATE()) ORDER BY discount_code");
    }
}