export type NotificationFilterId =
  | "all"
  | "like"
  | "comment"
  | "follow"
  | "post"
  | "academy"
  | "project"
  | "billboard"
  | "rating"
  | "ticket"
  | "system";

export const NOTIFICATION_FILTERS: Array<{
  id: NotificationFilterId;
  labelKey: string;
}> = [
  { id: "all", labelKey: "constants.notificationFilters.all" },
  { id: "like", labelKey: "constants.notificationFilters.like" },
  { id: "comment", labelKey: "constants.notificationFilters.comment" },
  { id: "follow", labelKey: "constants.notificationFilters.follow" },
  { id: "post", labelKey: "constants.notificationFilters.post" },
  { id: "academy", labelKey: "constants.notificationFilters.academy" },
  { id: "project", labelKey: "constants.notificationFilters.project" },
  { id: "billboard", labelKey: "constants.notificationFilters.billboard" },
  { id: "rating", labelKey: "constants.notificationFilters.rating" },
  { id: "ticket", labelKey: "constants.notificationFilters.ticket" },
  { id: "system", labelKey: "constants.notificationFilters.system" },
];

const LIKE_TYPES = new Set([
  "post_like",
  "academy_like",
  "billboard_like",
]);

const COMMENT_TYPES = new Set([
  "post_comment",
  "profile_comment",
  "user_comment",
  "academy_comment",
  "billboard_comment",
  "vitrine-comment",
]);

const FOLLOW_TYPES = new Set(["invite"]);

const POST_TYPES = new Set([
  "post_tag",
  "accept-post",
  "reject-post",
]);

const ACADEMY_TYPES = new Set([
  "academy_purchase",
]);

const PROJECT_TYPES = new Set([
  "request",
  "request_accepted",
  "recive-project",
  "accept-project",
  "reject-project",
  "end_project",
  "payment_progress",
  "new_offer",
  "offer",
]);

const BILLBOARD_TYPES = new Set(["vitrine"]);

const RATING_TYPES = new Set([
  "post_rating",
  "profile_rating",
  "academy_rating",
  "billboard_rating",
]);

const TICKET_TYPES = new Set(["ticket-message"]);

const SYSTEM_TYPES = new Set([
  "verify",
  "reject-user",
  "block",
  "not_register",
]);

export function notificationMatchesFilter(
  type: string,
  filter: NotificationFilterId
): boolean {
  if (filter === "all") return true;
  if (filter === "like") return LIKE_TYPES.has(type);
  if (filter === "comment") return COMMENT_TYPES.has(type);
  if (filter === "follow") return FOLLOW_TYPES.has(type);
  if (filter === "post") return POST_TYPES.has(type);
  if (filter === "academy") return type.startsWith("academy_") || ACADEMY_TYPES.has(type);
  if (filter === "project") return PROJECT_TYPES.has(type);
  if (filter === "billboard") return BILLBOARD_TYPES.has(type) || type.startsWith("billboard_");
  if (filter === "rating") return RATING_TYPES.has(type);
  if (filter === "ticket") return TICKET_TYPES.has(type);
  if (filter === "system") return SYSTEM_TYPES.has(type);
  return true;
}

export function getNotificationActionMeta(type: string): {
  icon: string;
  tint?: "red" | "green" | "blue" | "pink";
  labelKey: string;
} {
  if (LIKE_TYPES.has(type)) {
    return { icon: "heart", tint: "red", labelKey: "constants.notificationActions.like" };
  }
  if (COMMENT_TYPES.has(type)) {
    return { icon: "message", tint: "blue", labelKey: "constants.notificationActions.comment" };
  }
  if (RATING_TYPES.has(type)) {
    return { icon: "star", tint: "pink", labelKey: "constants.notificationActions.rating" };
  }
  if (type === "invite") {
    return { icon: "user-add", tint: "blue", labelKey: "constants.notificationActions.invite" };
  }
  if (type === "post_tag") {
    return { icon: "tag-user", tint: "blue", labelKey: "constants.notificationActions.tag" };
  }
  if (type === "accept-post" || type === "accept-project" || type === "request_accepted" || type === "vitrine") {
    return { icon: "tick-circle", tint: "green", labelKey: "constants.notificationActions.accept" };
  }
  if (type === "verify") {
    return { icon: "tick-circle", tint: "green", labelKey: "constants.notificationActions.accept" };
  }
  if (type === "reject-post" || type === "reject-project" || type === "reject-user") {
    return { icon: "close-circle", tint: "red", labelKey: "constants.notificationActions.reject" };
  }
  if (type === "new_offer" || type === "request" || type === "offer") {
    return { icon: "add", tint: "blue", labelKey: "constants.notificationActions.request" };
  }
  if (PROJECT_TYPES.has(type)) {
    return { icon: "briefcase", tint: "blue", labelKey: "constants.notificationActions.project" };
  }
  if (type.startsWith("academy_")) {
    return { icon: "teacher", tint: "pink", labelKey: "constants.notificationActions.academy" };
  }
  if (type.startsWith("billboard_") || BILLBOARD_TYPES.has(type)) {
    return { icon: "flash-circle", tint: "pink", labelKey: "constants.notificationActions.billboard" };
  }
  if (TICKET_TYPES.has(type)) {
    return { icon: "message-question", tint: "blue", labelKey: "constants.notificationActions.ticket" };
  }
  return { icon: "notification", labelKey: "constants.notificationActions.notification" };
}

/** آواتار کاربر یا آیکون موجودیت (پست / پروژه / بیلبورد / آموزشگاه) */
export function getNotificationVisualKind(
  type: string
): "user" | "post" | "project" | "billboard" | "academy" {
  if (type === "accept-post" || type === "reject-post" || type === "post_tag") {
    return "post";
  }
  if (
    type === "accept-project" ||
    type === "reject-project" ||
    type === "request" ||
    type === "request_accepted" ||
    type === "recive-project" ||
    type === "end_project" ||
    type === "payment_progress" ||
    type === "new_offer" ||
    type === "offer"
  ) {
    return "project";
  }
  if (type === "vitrine" || type === "vitrine-comment" || type.startsWith("billboard_")) {
    return "billboard";
  }
  if (type.startsWith("academy_")) {
    return "academy";
  }
  return "user";
}
