<?php
namespace App\Models;

use App\Core\Database;

final class PricingDistribution
{
    public static function activeAdherentsSummary(): array
    {
        $row=Database::connection()->query(
            "SELECT
                COUNT(*) AS total_actifs,
                SUM(CASE WHEN email IS NOT NULL AND email<>'' THEN 1 ELSE 0 END)
                    AS avec_email,
                SUM(CASE WHEN email IS NULL OR email='' THEN 1 ELSE 0 END)
                    AS sans_email
             FROM clients
             WHERE deleted_at IS NULL
               AND actif=1"
        )->fetch();

        return $row ?: [
            'total_actifs'=>0,
            'avec_email'=>0,
            'sans_email'=>0
        ];
    }

    public static function activeAdherents(): array
    {
        return Database::connection()->query(
            "SELECT id,code_client,nom,prenom,email
             FROM clients
             WHERE deleted_at IS NULL
               AND actif=1
             ORDER BY nom,prenom"
        )->fetchAll();
    }
}
