import { User } from "@/api";
import { IUser } from "@/api/resources/User";

export function mapIUserToLegacy(newUser: IUser): User.User {
  const legacyUser: User.User = {
    id: newUser._id || undefined,
    username: newUser.profile?.name ?? null,
    email: newUser.email || "",
    locale: newUser.locale || "",
    state: "",
    timezone: newUser.timezone || "",
    new_registration: false,
    stat: {
      last_online_at: null,
      prev_online_at: null,
    },
    profile: {
      full_name: newUser.profile?.name ?? null,
      gender: newUser.profile?.gender ?? null,
      birthday: newUser.profile?.birthdate ?? null,
      birthplace: newUser.profile?.birthplace?.address
        ? {
            id: "",
            address: newUser.profile.birthplace.address,
            coords: "",
          }
        : null,
      age: typeof newUser.profile?.age === "number"
        ? { years: newUser.profile.age, days: 0 }
        : null,
      sign: newUser.profile?.sign
        ? {
            house: 0,
            ruler: "",
            dates: {
              start: { month: 0, day: 0 },
              end: { month: 0, day: 0 },
            },
            sign: newUser.profile.sign,
            char: "",
            polarity: "",
            modality: "",
            triplicity: "",
          }
        : null,
      userpic: null,
      userpic_mime_type: undefined,
      relationship_status: "",
      human_relationship_status: "",
    },
    daily_push_subs: [],
  };

  return legacyUser;
}
