import { countries } from "country-data-list"
import { check_response, get_endpoint, type GenericResponse } from "./NovaAPI"

export const country_name = (country: string) => {
	if (country !== "" && countries[country] !== undefined) {
		return countries[country].emoji + " " + country + " (" + countries[country].name + ")"
	}
	return "🌐 Other"
}

export type Invoice = {
	id: string
	time: string
	amount: number
	vat: number
	processing_fee: number
	country: string
	payment_gateway: string
	payment_method: string
	status: string
}

export const get_admin_invoices = async (year: number, month: number) => {
	return await check_response(
		await fetch(
			get_endpoint() + "/admin/invoices/" + year + "-" + ("00" + (month)).slice(-2)
		)
	) as Invoice[]
};

export const admin_decommission_node = async (peer_id: string) => {
	let form = new FormData()
	form.set("peer_id", peer_id)

	return await check_response(
		await fetch(
			get_endpoint() + "/admin/decommission_node",
			{ method: "POST", body: form }
		)
	) as GenericResponse
};
