<?php
class Offer {
    private $conn;
    private $table_name = "offers";

    public $id;
    public $title;
    public $description;
    public $discount_type;
    public $discount_value;
    public $image;
    public $start_date;
    public $end_date;
    public $is_active;
    public $priority;

    public function __construct($db) {
        $this->conn = $db;
    }

    // Read all active offers
    public function readAllActive() {
        $query = "SELECT * FROM " . $this->table_name . "
                WHERE is_active = 1 
                AND (start_date IS NULL OR start_date <= NOW())
                AND (end_date IS NULL OR end_date >= NOW())
                ORDER BY priority DESC, created_at DESC";

        $stmt = $this->conn->prepare($query);
        $stmt->execute();

        return $stmt;
    }
}
?>
