export function apiEnvelope<T>(data: T) {
  return {
    code: 200,
    message: "success",
    success: true,
    data,
  };
}

export const e2eUser = {
  id: "user_e2e",
  username: "E2E User",
  email: "e2e@example.com",
  platform: "web",
  intimacy: 42,
  dolBalance: 0,
  relationshipStage: "close_friend",
  currentMood: "happy",
  preferredLanguage: "en",
  createdAt: "2026-06-25T00:00:00.000Z",
  lastMessageAt: "",
  avatarUrl: "",
  loginProvider: "guest",
  isGuest: true,
  isVip: false,
  voiceMinutesRemaining: 0,
};

export const e2eEmailUser = {
  ...e2eUser,
  id: "user_e2e_email",
  username: "E2E Email User",
  email: "chanwillian0@gmail.com",
  isGuest: false,
};

export const guestLoginResponse = {
  token: "e2e-guest-token",
  deviceId: "e2e-device-id",
  userId: e2eUser.id,
  isDeviceUser: true,
  expiresIn: 2_592_000,
  user: e2eUser,
};

export const emailLoginResponse = {
  token: "e2e-email-token",
  refreshToken: "e2e-email-refresh-token",
  user: e2eEmailUser,
};

export const userEntitlementsResponse = {
  userId: e2eEmailUser.id,
  isGuest: false,
  isVip: false,
  vipExpiresAt: null,
  creditBalance: 0,
  dolBalance: 0,
};

export const emptyChatHistoryResponse = {
  messages: [],
  total: 0,
  limit: 50,
  offset: 0,
  isVip: false,
  privateFreeLimit: 0,
  privateUsedToday: 0,
  privateCanViewFree: false,
};

export const chatSendResponse = {
  reply: "Hello from the E2E boyfriend.",
  audioUrl: "",
  messageId: "msg_e2e_reply_001",
  isGuest: true,
  timestamp: 1_782_356_425_363,
  image: {
    type: null,
    url: null,
  },
  lockDetail: {
    locked: false,
    showContent: true,
    showUpgrade: false,
    reason: null,
    hint: null,
    detail: null,
  },
};

export function createChatSendResponse(sendCount: number) {
  return {
    ...chatSendResponse,
    reply: `Hello from the E2E boyfriend. Reply ${sendCount}.`,
    messageId: `msg_e2e_reply_${String(sendCount).padStart(3, "0")}`,
    timestamp: chatSendResponse.timestamp + sendCount,
  };
}

export function createWeeklyLimitChatSendResponse(
  usedMessageCount: number,
  limit: number,
) {
  return {
    reply: "",
    audioUrl: "",
    messageId: "",
    isGuest: true,
    timestamp: chatSendResponse.timestamp + usedMessageCount,
    image: {
      type: null,
      url: null,
    },
    lockDetail: {
      locked: true,
      showContent: false,
      showUpgrade: true,
      reason: "weekly_limit",
      hint: "Free message limit reached.",
      detail: {
        type: "weekly_msg_limit",
        usedThisWeek: usedMessageCount,
        limit,
      },
    },
  };
}

export const paymentPlansResponse = {
  plans: [
    {
      plan_id: "vip_monthly",
      plan_name: "Monthly",
      order_type: "vip_monthly",
      amount_cents: 999,
      original_amount_cents: 1999,
      daily_price_cents: 33,
      currency: "USD",
      vip_days: 30,
      dol_amount: null,
    },
    {
      plan_id: "vip_quarterly",
      plan_name: "Quarterly",
      order_type: "vip_quarterly",
      amount_cents: 2499,
      original_amount_cents: 5999,
      daily_price_cents: 28,
      currency: "USD",
      vip_days: 90,
      dol_amount: null,
    },
    {
      plan_id: "dol_voice_30",
      plan_name: "Voice Pack",
      order_type: "dol_voice",
      amount_cents: 499,
      original_amount_cents: null,
      daily_price_cents: null,
      currency: "USD",
      vip_days: null,
      dol_amount: 30,
    },
  ],
};

export const paymentOrderId = "order_e2e_vip_monthly";

export const createPaymentOrderResponse = {
  orderId: paymentOrderId,
  payParams: {
    provider: "stripe",
    clientSecret: "pi_e2e_secret_mock",
  },
};

export const paidPaymentOrderStatusResponse = {
  orderId: paymentOrderId,
  status: "paid",
  orderType: "vip_monthly",
  planId: "vip_monthly",
};

export const vipStatusResponse = {
  isVip: false,
  expiresAt: null,
};
