package com.bitnix.dirtcryptostore.model;

import java.util.ArrayList;
import java.util.List;

public class Product {

    private final String id;
    private final boolean enabled;
    private final String displayName;
    private final String materialName;
    private final int customModelData;
    private final boolean glow;
    private final int slot;
    private final String wallet;
    private final double priceUsd;
    private final long baseSats;
    private final String permissionRequired;
    private final boolean purchasableOnce;
    private final List<String> commands;
    private final List<String> lore;

    public Product(String id,
                   boolean enabled,
                   String displayName,
                   String materialName,
                   int customModelData,
                   boolean glow,
                   int slot,
                   String wallet,
                   double priceUsd,
                   long baseSats,
                   String permissionRequired,
                   boolean purchasableOnce,
                   List<String> commands,
                   List<String> lore) {
        this.id = id;
        this.enabled = enabled;
        this.displayName = displayName;
        this.materialName = materialName;
        this.customModelData = customModelData;
        this.glow = glow;
        this.slot = slot;
        this.wallet = wallet;
        this.priceUsd = priceUsd;
        this.baseSats = baseSats;
        this.permissionRequired = permissionRequired == null ? "" : permissionRequired;
        this.purchasableOnce = purchasableOnce;
        this.commands = commands == null ? new ArrayList<>() : new ArrayList<>(commands);
        this.lore = lore == null ? new ArrayList<>() : new ArrayList<>(lore);
    }

    public String getId() {
        return id;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public String getDisplayName() {
        return displayName;
    }

    public String getMaterialName() {
        return materialName;
    }

    public int getCustomModelData() {
        return customModelData;
    }

    public boolean isGlow() {
        return glow;
    }

    public int getSlot() {
        return slot;
    }

    public String getWallet() {
        return wallet;
    }

    public double getPriceUsd() {
        return priceUsd;
    }

    public long getBaseSats() {
        return baseSats;
    }

    public String getPermissionRequired() {
        return permissionRequired;
    }

    public boolean isPurchasableOnce() {
        return purchasableOnce;
    }

    public List<String> getCommands() {
        return new ArrayList<>(commands);
    }

    public List<String> getLore() {
        return new ArrayList<>(lore);
    }

    public String formatBtcAmount(long sats) {
        long whole = sats / 100_000_000L;
        long fractional = sats % 100_000_000L;
        return whole + "." + String.format("%08d", fractional) + " BTC";
    }

    public String formatBitcoinUri(long sats, String address) {
        long whole = sats / 100_000_000L;
        long fractional = sats % 100_000_000L;
        String amount = whole + "." + String.format("%08d", fractional);
        return "bitcoin:" + address + "?amount=" + amount;
    }
}
