import type { FormattedQuoteResponse } from "@hooks/apis/common/quote/types";
import { logEvent } from "./gtag";

export type TrackOrderStatus = {
	status: "success" | "failed";
	from_token: string;
	to_token: string;
	from_chain: number;
	to_chain: number;
	routingMode:
		| "auto-same-chain"
		| "auto-cross-chain"
		| "manual-same-chain"
		| "manual-cross-chain"
		| (string & {});
	flowType: "bundled" | "regular";
	slippage?: string | number;
	suggestedClientSlippage?: boolean;
};

export function trackOrderStatus(data: TrackOrderStatus) {
	logEvent("order_status", data);
}

export type OnConnectWallet = {
	wallet_type: "EVM" | "SVM";
	wallet_name: string;
	total_balance: number;
};

export const onConnectWallet = (data: OnConnectWallet) => {
	logEvent("connect_wallet", data);
};

export type OnRequestQuote = {
	source_chain_id: number;
	destination_chain_id: number;
	source_token_symbol: string;
	destination_token_symbol: string;
	input_amount: number | undefined;
};

export const onRequestQuote = (data: OnRequestQuote) => {
	logEvent("request_quote", data);
};

export type OnQuoteResult = {
	status: "success" | "no_quotes_returned" | "error";
	source_chain_id: number | undefined;
	destination_chain_id: number | undefined;
	source_token_symbol: string | undefined;
	destination_token_symbol: string | undefined;
	input_amount: number | undefined;
	quote_count: number;
	fastest_option: FormattedQuoteResponse | undefined;
	bestoutput_option: FormattedQuoteResponse | undefined;
	default_selected: FormattedQuoteResponse | undefined;
};

export const onQuoteResult = (data: OnQuoteResult) => {
	logEvent("quote_result", data);
};

export const onViewRouteComparison = () => {
	logEvent("view_route_comparison");
};

export type OnSetCustomRecipient = {
	enabled: boolean;
};

export const onSetCustomRecipient = (data: OnSetCustomRecipient) => {
	logEvent("set_custom_recipient", data);
};

export type OnToggleRefuel = {
	enabled: boolean;
};

export const onToggleRefuel = (data: OnToggleRefuel) => {
	logEvent("toggle_refuel", data);
};

export type OnSelectRoute = {
	provider_name: string;
	source_chain_id: number;
	destination_chain_id: number;
	source_token_symbol: string;
	destination_token_symbol: string;
	input_amount_usd: number;
	estimated_output_amount: number;
	estimated_time: number;
	provider_best_output: number;
	provider_name_best_output?: string;
	provider_best_time: number;
};

export const onSelectRoute = (data: OnSelectRoute) => {
	logEvent("select_route", data);
};

export type OnTokenApproved = {
	token_symbol: string;
	chain_id: number;
	contract: "gateway" | "permit2";
};

export const onTokenApproved = (data: OnTokenApproved) => {
	logEvent("token_approved", data);
};

export type OnViewSwapReviewScreen = {
	provider_name: string;
	source_chain_id: number;
	destination_chain_id: number;
	source_token_symbol: string;
	destination_token_symbol: string;
	input_amount_usd: number;
	estimated_output_amount: number;
	estimated_time: number;
};

export const onViewSwapReviewScreen = (data: OnViewSwapReviewScreen) => {
	logEvent("view_swap_review_screen", data);
};

export type OnInitiateSwap = {
	request_hash: string;
	provider_name: string;
	source_chain_id: number;
	destination_chain_id: number;
	has_refuel: boolean;
	has_custom_recipient: boolean;
	source_token_symbol: string;
	destination_token_symbol: string;
	input_amount_usd: number;
};

export const onInitiateSwap = (data: OnInitiateSwap) => {
	logEvent("initiate_swap", data);
};

export type OnCompleteSwap = {
	status: "success" | "failed";
	request_hash: string;
	provider_name: string;
	actual_time_seconds: number;
	actual_output_amount: number;
	estimated_time_seconds: number;
	estimated_output_amount: number;
};

export const onCompleteSwap = (data: OnCompleteSwap) => {
	logEvent("complete_swap", data);
};
