// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

use std::num::NonZero;

use crate::traits::ForInventory;

const MAX_PAGE_SIZE: NonZero<usize> = NonZero::new(1000).unwrap();

impl ForInventory for pib_service_facade::paging::Pagination {
    type InventoryType = pib_service_inventory::Pagination;

    fn for_inventory(self) -> Self::InventoryType {
        let pib_service_facade::paging::Pagination { page, per_page } = self;
        pib_service_inventory::Pagination {
            page: page.into(),
            per_page: std::cmp::min(per_page.into(), MAX_PAGE_SIZE),
        }
    }
}
