#!/usr/bin/env python
"""
Shop Manager Module

This module contains all shop and store-related functionality for BaoLife.
It manages in-game store items and in-app purchase items.

Classes:
    - StoreItem: Represents items available for purchase with in-game currency
    - InAppPurchaseItem: Represents items available for real money purchase

Functions:
    - getStoreItems(): Returns list of all available store items
    - purchaseItem(player, itemID): Handles purchase of store items with in-game money
    - getInAppPurchaseItems(): Returns list of all in-app purchase items
    - purchaseInAppItem(player, itemID): Handles in-app purchase transactions

Extracted from: ws/functions.py
Original line numbers: 2756-2861
"""

import uuid


class StoreItem:
    """
    Represents an item available for purchase in the in-game store.

    Attributes:
        id (str): Unique identifier (UUID hex)
        name (str): Display name of the item
        image (str): URL to item image
        price (int): Cost in in-game currency
        description (str): Item description text
        prestigeBoost (int): Amount of prestige gained when purchased
        energyBoost (int): Amount of energy gained when purchased (0 if permanent item)
    """

    def __init__(self, name, price, description, prestigeBoost, image=None, energyBoost=0):
        # generate id
        self.id = uuid.uuid4().hex
        self.name = name
        self.image = image
        self.price = price
        self.description = description
        self.prestigeBoost = prestigeBoost
        self.energyBoost = energyBoost


def getStoreItems():
    """
    Returns a list of all available store items.

    Items include luxury goods, experiences, and energy boosts that can be
    purchased with in-game currency to increase prestige or energy.

    Returns:
        list[StoreItem]: List of all available store items
    """
    items = [
        StoreItem("Case of Energy Drinks", 100, "Gives you a +20 energy boost", 0, "https://media.discordapp.net/attachments/1106614533402931284/1187548155630329937/craig_vg_cozy_cartoon-style_image_of_a_pack_of_energy_drinks._T_bee4a32e-9d74-422c-813a-a20c1a198c5f.png?ex=66060767&is=65f39267&hm=afa75cf6bc2477fed66536b28371988a1e29dd9d835d0fc31a9834bc83980319&=&format=png&quality=lossless&width=526&height=526", 20),
        StoreItem("Sports Car", 50000, "A shiny new sports car to show off.", 50, "https://v3b.fal.media/files/b/zebra/qZXW3UgLfqPzkOKvkJeOt_output.png"),
        StoreItem("Luxury Phone", 20000, "A state-of-the-art smartphone with the latest technology.", 20),
        StoreItem("Designer Suit", 7000, "A designer suit to make a great impression.", 15, "https://v3b.fal.media/files/b/penguin/rt2iZVcC_9kSe8B29V3ak_output.png"),
        StoreItem("Luxury Watch", 10000, "A timeless piece of fine craftsmanship.", 25),
        StoreItem("High-End Laptop", 25000, "A high-performance laptop for both work and play.", 35),
        StoreItem("Artisan Coffee Machine", 4000, "Make perfect coffee every time.", 10, "https://v3b.fal.media/files/b/monkey/G9qa80OkcyEnDjWjKm8q4_output.png"),
        StoreItem("Luxury Yacht", 200000, "A personal luxury yacht for parties and more.", 100),
        StoreItem("Private Jet", 300000, "Travel in style and comfort with a private jet.", 150),
        StoreItem("Designer Handbag", 5000, "A handbag from a famous designer.", 10, "https://v3b.fal.media/files/b/panda/i4G7JcMyYH8sP1qCaSmaZ_output.png"),
        StoreItem("Diamond Ring", 8000, "A dazzling ring with a large diamond.", 20, "https://v3b.fal.media/files/b/tiger/XjFTzmkaa0ILumrKOcTK3_output.png"),
        StoreItem("Personal Island", 500000, "Your very own island paradise.", 200),
        StoreItem("Luxury Villa", 150000, "A luxurious villa in a prime location.", 75),
        StoreItem("Exotic Pet", 15000, "A unique pet to accompany your journey.", 30),
        StoreItem("Gourmet Chef", 12000, "Hire a gourmet chef to cook your meals.", 25),
        StoreItem("Famous Painting", 40000, "An original painting from a famous artist.", 40),
        StoreItem("Rare Wine", 5000, "A bottle of rare and vintage wine.", 10, "https://v3b.fal.media/files/b/koala/OePvHz6E3K8XTRtrjzQt7_output.png"),
        StoreItem("Limited Edition Sneakers", 3000, "Limited edition sneakers from a high-end brand.", 8, "https://v3b.fal.media/files/b/panda/_SWcVFQ-SqyLHSQuU_Uq__output.png"),
        StoreItem("Luxury Skincare Set", 2000, "A luxury skincare set for ultimate pampering.", 7),
        StoreItem("Concert Tickets", 2500, "Tickets to see your favorite artist live.", 8),
        StoreItem("Custom-Made Dress", 7000, "A custom-made dress from a renowned designer.", 15),
        StoreItem("High-End Stereo System", 8000, "A high-end stereo system for the best audio experience.", 20),
        StoreItem("Designer Sunglasses", 1500, "Stylish sunglasses from a famous brand.", 5, "https://v3b.fal.media/files/b/lion/vcw1faj-Iwe3KsBtkKi09_output.png"),
        StoreItem("Five Star Vacation", 10000, "An all-inclusive vacation at a five-star resort.", 25),
        StoreItem("Fitness Membership", 3000, "Membership to a high-end fitness club.", 10),
        StoreItem("Gourmet Kitchen Set", 15000, "A set of top-notch kitchen appliances.", 25),
        StoreItem("Home Theatre System", 20000, "Turn your home into a personal cinema.", 30),
        StoreItem("Vintage Guitar", 10000, "A beautiful vintage guitar for music lovers.", 20),
        StoreItem("Designer Furniture Set", 30000, "Furnish your home with a unique designer touch.", 35),
        StoreItem("Luxury Fragrance", 5000, "A signature scent from a high-end brand.", 10, "https://v3b.fal.media/files/b/rabbit/KLB-SKDI3SEWLV6vnRpT-_output.png"),
        StoreItem("Antique Chess Set", 3000, "An antique chess set for intellectual stimulation.", 7),
        StoreItem("Rare Book Collection", 7000, "A collection of rare and valuable books.", 15),
        StoreItem("Upscale Pet House", 4000, "A deluxe house for your pet.", 10),
        StoreItem("Orchard Garden", 10000, "Grow your own fruit in your backyard.", 20),
        StoreItem("Private Helicopter", 100000, "Get to your destination in no time with a private helicopter.", 75),
        StoreItem("Gold-Plated Pool Table", 12000, "A pool table with a golden touch.", 20),
        StoreItem("Smart Home System", 25000, "Turn your home into a smart home with the latest technology.", 30),
        StoreItem("Rare Comic Collection", 5000, "A collection of rare and vintage comic books.", 10),
        StoreItem("Collector's Edition Board Games", 4000, "Collector's edition versions of popular board games.", 10),
        StoreItem("Home Recording Studio", 30000, "Create your own music with a home recording studio.", 35),
        StoreItem("Advanced Drone", 8000, "An advanced drone for capturing high-quality footage.", 20),
        StoreItem("Luxury Hot Tub", 15000, "Relax in style with a luxury hot tub.", 25),
        StoreItem("Designer Watch", 20000, "A designer watch that makes a statement.", 30),
        StoreItem("Platinum Credit Card", 10000, "A platinum credit card with a high spending limit.", 20),
        StoreItem("Personal Robot", 50000, "A personal robot to assist with daily tasks.", 50),
        StoreItem("Crystal Chandelier", 8000, "Add a touch of elegance to your home with a crystal chandelier.", 20),
        StoreItem("Italian Leather Sofa", 7000, "A luxurious Italian leather sofa for your living room.", 15),
        StoreItem("Skydiving Experience", 3000, "Experience the thrill of skydiving.", 10),
        StoreItem("Space Travel Ticket", 100000, "Travel to space for an unforgettable experience.", 100),
        StoreItem("Virtual Reality System", 5000, "Experience the future of gaming with a virtual reality system.", 15),
    ]
    return items


def purchaseItem(player, itemID):
    """
    Processes the purchase of a store item.

    Checks if player has sufficient funds, deducts the price, and applies
    item benefits (prestige boost, energy boost, or adds to inventory).

    Args:
        player: The player object containing character and store data
        itemID (str): The unique identifier of the item to purchase

    Returns:
        bool: True if purchase successful, False if insufficient funds or item not found
    """
    # Import here to avoid circular dependency
    from stats.stats_manager import getPeakEnergy

    for item in player.storeItems:
        if item.id == itemID:
            if player.c.money >= item.price:
                player.c.money -= item.price
                player.c.prestige += item.prestigeBoost
                if (item.energyBoost > 0):
                    player.c.energy += item.energyBoost
                    getPeakEnergy(player.c)
                else:
                    player.c.items.append(item)
                return True
            else:
                return False
    return False


class InAppPurchaseItem:
    """
    Represents an item available for purchase with real money.

    Attributes:
        id (str): Unique identifier
        name (str): Display name of the item
        price (float): Real money price (USD)
        description (str): Item description text
        diamonds (int): Number of diamonds awarded
        image (str): URL to item image
    """

    def __init__(self, id, name, price, description, diamonds, image=None):
        self.id = id
        self.name = name
        self.price = price
        self.description = description
        self.diamonds = diamonds
        self.image = "https://v3b.fal.media/files/b/tiger/Jxcl60OfljvE7E8kmrsF1_output.png"


def getInAppPurchaseItems():
    """
    Returns a list of all available in-app purchase items.

    These items represent diamond packs that can be purchased with real money
    to obtain premium in-game currency.

    Returns:
        list[InAppPurchaseItem]: List of all available in-app purchase items
    """
    items = [
        InAppPurchaseItem("item1", "Diamond Pack 1", 0.99, "Get 100 diamonds!", 100, "https://v3b.fal.media/files/b/tiger/Jxcl60OfljvE7E8kmrsF1_output.png"),
        InAppPurchaseItem("item2", "Diamond Pack 2", 1.99, "Get 210 diamonds!", 210, "https://v3b.fal.media/files/b/tiger/Jxcl60OfljvE7E8kmrsF1_output.png"),
        InAppPurchaseItem("item3", "Diamond Pack 3", 2.99, "Get 330 diamonds!", 330),
        InAppPurchaseItem("item4", "Diamond Pack 4", 3.99, "Get 460 diamonds!", 460),
        InAppPurchaseItem("item5", "Diamond Pack 5", 4.99, "Get 600 diamonds!", 600),
    ]
    return items


def purchaseInAppItem(player, itemID):
    """
    Processes an in-app purchase transaction.

    Awards diamonds to the player's character based on the purchased item.
    Note: Actual payment processing happens elsewhere; this only awards the diamonds.

    Args:
        player: The player object containing character data
        itemID (str): The unique identifier of the in-app purchase item

    Returns:
        bool: Always returns False (legacy behavior)
    """
    for item in getInAppPurchaseItems():
        if item.id == itemID:
            player.c.diamonds += item.diamonds
    return False
