<?php

namespace App\Services\Discounts;

use App\Models\DiscountUsage;
use App\Models\User;

class DiscountParentService
{
    public function listParentsWithDiscounts(string $schoolYear): array
    {
        $parents = User::getParents();

        foreach ($parents as &$parent) {
            $total = DiscountUsage::getTotalDiscountByParentIdAndSchoolYear(
                (int) ($parent['id'] ?? 0),
                $schoolYear
            );

            $parent['total_discount'] = $total;
            $parent['has_discount'] = $total > 0 ? 1 : 0;
        }
        unset($parent);

        return $parents;
    }
}
