<?php

class Promotion extends Model
{
    protected string $table = 'promotions';

    public function allOrdered(): array
    {
        return $this->db->query(
            "SELECT * FROM promotions ORDER BY is_active DESC, display_order ASC, id ASC"
        )->fetchAll();
    }

    public function activeOrdered(): array
    {
        return $this->db->query(
            "SELECT * FROM promotions WHERE is_active = 1 ORDER BY display_order ASC, id ASC"
        )->fetchAll();
    }

    public function nextDisplayOrder(): int
    {
        $stmt = $this->db->query("SELECT COALESCE(MAX(display_order),0) + 1 as next_order FROM promotions");
        return (int) $stmt->fetch()['next_order'];
    }
}
