export interface ReplyItem {
  id: string;
  contactPhone: string;
  originalMessage: string;
  replyMessage: string;
  replyTime: string;
  source: "sms" | "manual";
  unread: boolean;
}

export const REPLY_PAGE_SIZE = 6;

export const REPLY_SOURCE_META: Record<ReplyItem["source"], { text: string; className: string }> = {
  sms: {
    text: "短信回复",
    className: "source-sms",
  },
  manual: {
    text: "人工传话",
    className: "source-manual",
  },
};

export const MOCK_REPLY_LIST: ReplyItem[] = [
  {
    id: "RP250503001",
    contactPhone: "19878384602",
    originalMessage: "有些话想认真说一次，不打扰你，只希望你知道我的歉意。",
    replyMessage: "我收到了。谢谢你愿意认真说这些，我需要一点时间想想。",
    replyTime: "2026-05-03 20:12:00",
    source: "sms",
    unread: true,
  },
  {
    id: "RP250503002",
    contactPhone: "13993621665",
    originalMessage: "之前没有照顾好你的感受，对不起。愿你之后都能轻松一点。",
    replyMessage: "我已经看到了，也希望你之后能真的慢慢变好。",
    replyTime: "2026-05-03 18:35:00",
    source: "manual",
    unread: true,
  },
  {
    id: "RP250502003",
    contactPhone: "18826830915",
    originalMessage: "如果还有机会，我想把没说好的话认真补上。",
    replyMessage: "先不用急着见面，等彼此都平静一点再说吧。",
    replyTime: "2026-05-02 21:08:00",
    source: "sms",
    unread: false,
  },
  {
    id: "RP250501004",
    contactPhone: "15188340219",
    originalMessage: "这条短信只是想把心意说清楚，不给你压力。",
    replyMessage: "谢谢你的祝福，我也希望我们都能好好生活。",
    replyTime: "2026-05-01 09:46:00",
    source: "sms",
    unread: false,
  },
  {
    id: "RP250430005",
    contactPhone: "13677268104",
    originalMessage: "对不起，之前的争吵我也有很多没有处理好的地方。",
    replyMessage: "我知道了。过去的事情先放一放吧，别再互相消耗了。",
    replyTime: "2026-04-30 22:20:00",
    source: "manual",
    unread: false,
  },
  {
    id: "RP250429006",
    contactPhone: "19945201866",
    originalMessage: "想把晚安认真补给你，也想把歉意说清楚。",
    replyMessage: "晚安。也祝你以后能遇到更好的自己。",
    replyTime: "2026-04-29 23:17:00",
    source: "sms",
    unread: false,
  },
  {
    id: "RP250428007",
    contactPhone: "16690438152",
    originalMessage: "我不会再频繁打扰，只是想最后认真表达一次。",
    replyMessage: "收到。谢谢你尊重我的节奏。",
    replyTime: "2026-04-28 16:02:00",
    source: "manual",
    unread: false,
  },
];

export const serializeReply = (reply: ReplyItem): string => encodeURIComponent(JSON.stringify(reply));

export const deserializeReply = (payload?: string): ReplyItem | null => {
  if (!payload) return null;

  try {
    return JSON.parse(decodeURIComponent(payload)) as ReplyItem;
  } catch (error) {
    console.error("解析回复详情失败", error);
    return null;
  }
};
