import type { CustomTheme, Tables, XRankPlacementRegion } from "~/db/tables";
import type { StageId } from "~/modules/in-game-lists/types";
import type { CommonUser } from "~/utils/kysely.server";
import type { TieredSkill } from "../mmr/tiered.server";

export interface UserCardData extends CommonUser {
	banner: UserCarBannerData;
	shortBio: string | null;
	customTheme: CustomTheme | null;
	friendCode: string | null;
	/** Id of the user's free agent LFG post, or `null` if they have none. */
	freeAgentPostId: number | null;
	/** The viewer's private note about this user, or `null` when they have none. */
	privateNote: Pick<
		Tables["PrivateUserNote"],
		"text" | "sentiment" | "updatedAt"
	> | null;
	stats: Array<UserCardStat>;
}

/**
 * Viewer-relative card fields lazy-loaded when the card opens (see the
 * `/user-card/:id/friendship` resource route), kept out of the batched `UserCardData`
 * query because they are only needed for the one card a viewer actually opens.
 */
export interface UserCardFriendship {
	isFriend: boolean;
	/** Whether the viewer has a pending friend request sent to this user. */
	sentFriendRequest: boolean;
	/** Id of this user's pending friend request to the viewer, or `null` when there is none. */
	incomingFriendRequestId: number | null;
	mutualFriends: Array<CommonUser>;
}

type UserCarBannerData =
	| {
			type: "URL";
			url: string;
	  }
	| {
			type: "COLOR";
			hexCode: string;
	  }
	| {
			type: "STAGE";
			stageId: StageId;
	  };

export type UserCardStat =
	| {
			type: "XP";
			values: Array<UserCardStatXPValue>;
	  }
	| {
			type: "DIV";
			value: string;
	  }
	| {
			type: "PLUS";
			value: number;
	  }
	| {
			type: "SEASON";
			value: TieredSkill["tier"];
			top: number | null;
	  };

export interface UserCardStatXPValue {
	isVerified: boolean;
	region: XRankPlacementRegion;
	points: number;
}
