"""Shared serializer helper functions used across multiple apps."""


def ammo_detail(ammo):
    if ammo is None:
        return None
    cal = ammo.caliber
    return {
        'id': ammo.id, 'brand': ammo.brand, 'name': ammo.name,
        'caliber_detail': {'id': cal.id, 'name': cal.name} if cal else None,
    }


def batch_detail(batch):
    if batch is None:
        return None
    return {
        'id': batch.id,
        'recipe_name': batch.recipe.name,
        'powder': str(batch.powder),
        'powder_charge_gr': str(batch.powder_charge_gr),
    }
