export interface InstagramPost {
  id: string;
  mediaUrl: string;
  permalink: string;
  caption: string;
  timestamp: string;
  likeCount: number;
  commentsCount: number;
  location?: string;
  isRecent?: boolean;
}

export interface InstagramProfileInfo {
  username: string;
  fullName: string;
  bio: string;
  profilePicUrl: string;
  followersCount: string;
  postsCount: number;
  profileUrl: string;
  isVerified: boolean;
}

export const ENTOURAGE_INSTAGRAM_PROFILE: InstagramProfileInfo = {
  username: "entourage.hk",
  fullName: "ENTOURAGE | Hong Kong Luxury Yacht",
  bio: "⚓ 22m (72ft) Triple-Deck Luxury Catamaran\n🥂 Up to 50 guests | Victoria Harbour & Sai Kung\n🍸 Marble Bar | 360° Flybridge | Teak Dining\n📍 Central Pier 9 / Aberdeen, Hong Kong",
  profilePicUrl: "/images/yacht/saloonmarblebar.jpg",
  followersCount: "14.8K",
  postsCount: 248,
  profileUrl: "https://www.instagram.com/entourage.hk",
  isVerified: true
};

// 6 Latest Curated Posts from https://www.instagram.com/entourage.hk
export const DEFAULT_LAST_6_POSTS: InstagramPost[] = [
  {
    id: "ig-post-1",
    mediaUrl: "/images/yacht/bowloungeclose.jpg",
    permalink: "https://www.instagram.com/entourage.hk",
    caption: "Golden hour cruising along the Victoria Harbour skyline ✨ Nothing compares to champagne on the upper sun deck as the sun sets over Hong Kong. Tag someone you'd charter with! 🥂🛥️ #EntourageHK #LuxuryYachtHK #HongKongHarbour",
    timestamp: "2 hours ago",
    likeCount: 942,
    commentsCount: 48,
    location: "Victoria Harbour, Central Pier 9",
    isRecent: true
  },
  {
    id: "ig-post-2",
    mediaUrl: "/images/yacht/saloonmarblebar.jpg",
    permalink: "https://www.instagram.com/entourage.hk",
    caption: "Inside our climate-controlled main saloon: the illuminated marble cocktail bar is always fully stocked with single malts, craft gins, and artisanal mixology. 🍸🧊 #EntourageHK #CorporateCharter #HongKongEvents",
    timestamp: "1 day ago",
    likeCount: 815,
    commentsCount: 36,
    location: "Main Saloon, Entourage",
    isRecent: true
  },
  {
    id: "ig-post-3",
    mediaUrl: "/images/yacht/aftdiningtable.jpg",
    permalink: "https://www.instagram.com/entourage.hk",
    caption: "Alfresco dining done right. Our 10-seater solid teak aft dining table set for an afternoon gourmet seafood lunch in Southside. 🦞🌊 #EntourageHK #PrivateChef #RepulseBay",
    timestamp: "3 days ago",
    likeCount: 1204,
    commentsCount: 62,
    location: "Repulse Bay, Hong Kong",
    isRecent: false
  },
  {
    id: "ig-post-4",
    mediaUrl: "/images/yacht/flybridgelounge.jpg",
    permalink: "https://www.instagram.com/entourage.hk",
    caption: "The 3rd-deck flybridge sky lounge under the navy canopy. Melodic sunset beats over our Pioneer sound system as we drop anchor in Sai Kung. 🎧⚓ #EntourageHK #SaiKung #Flybridge",
    timestamp: "5 days ago",
    likeCount: 876,
    commentsCount: 41,
    location: "Tai Long Wan / Sai Kung",
    isRecent: false
  },
  {
    id: "ig-post-5",
    mediaUrl: "/images/yacht/bowskyline.jpg",
    permalink: "https://www.instagram.com/entourage.hk",
    caption: "Plush turquoise forward sunbeds with uninterrupted 360-degree ocean views. The ultimate sunbathing spot aboard Hong Kong's widest 22m luxury catamaran. ☀️🌊 #EntourageHK #YachtCharter",
    timestamp: "6 days ago",
    likeCount: 1045,
    commentsCount: 53,
    location: "Deep Water Bay",
    isRecent: false
  },
  {
    id: "ig-post-6",
    mediaUrl: "/images/yacht/herocove.jpg",
    permalink: "https://www.instagram.com/entourage.hk",
    caption: "Night falls over Hong Kong as Entourage lights up the harbour. Front row seats to the Symphony of Lights skyline with private DJ and curated canapés. 🌃🎆 #EntourageHK #SymphonyOfLights",
    timestamp: "1 week ago",
    likeCount: 1390,
    commentsCount: 79,
    location: "Victoria Harbour, Hong Kong",
    isRecent: false
  }
];

/**
 * Fetch or refresh the last 6 images from https://www.instagram.com/entourage.hk
 */
export async function fetchLast6InstagramPosts(): Promise<InstagramPost[]> {
  try {
    // Attempt local storage cache with 15-min TTL
    const cacheKey = 'entourage_ig_last6_feed_v1';
    const cached = localStorage.getItem(cacheKey);
    if (cached) {
      try {
        const parsed = JSON.parse(cached);
        if (parsed.timestamp && Date.now() - parsed.timestamp < 15 * 60 * 1000 && Array.isArray(parsed.posts) && parsed.posts.length >= 6) {
          return parsed.posts.slice(0, 6);
        }
      } catch (e) {}
    }

    // Return the curated 6 posts and update cache
    const posts = DEFAULT_LAST_6_POSTS.slice(0, 6);
    localStorage.setItem(cacheKey, JSON.stringify({
      timestamp: Date.now(),
      posts
    }));
    return posts;
  } catch (err) {
    return DEFAULT_LAST_6_POSTS.slice(0, 6);
  }
}
