<?php

class DeliveryZone extends Model
{
    protected string $table = 'delivery_zones';

    public function activeZones(): array
    {
        return $this->db->query(
            "SELECT * FROM delivery_zones WHERE is_active = 1 ORDER BY zone_name ASC"
        )->fetchAll();
    }

    public function allZones(): array
    {
        return $this->db->query(
            "SELECT dz.*,
                    (SELECT COUNT(*) FROM orders o WHERE o.delivery_zone_id = dz.id) as order_count
             FROM delivery_zones dz ORDER BY dz.is_active DESC, dz.zone_name ASC"
        )->fetchAll();
    }
}
