const LogRepository = require('../../repository/superadmin/LogRepository.js');
const { SearchFilter } = require('../../utils/SearchFilter.js');

exports.getAllLogsService = async ({ page, limit, search, sortBy, orderBy }) => {
    const skip = (page - 1) * limit;

    const where = {
        ...SearchFilter(search, ['username', 'action']),
        deletedAt: null
    };

    const [logs, total] = await Promise.all([
        LogRepository.findAll({ skip, take: limit, where, orderBy: { [sortBy]: orderBy } }),
        LogRepository.countAll(where)
    ]);

    return { logs, total };
};