// Farming for Blockheads Market Listings
// Adds Croptopia seeds and saplings to the market block.
// Uses event.custom() approach (same as ATM10).

ServerEvents.recipes(event => {
    // Croptopia seeds
    let croptopiaSeeds = [
        'artichoke', 'asparagus', 'barley', 'basil', 'bellpepper', 'blackbean',
        'blackberry', 'blueberry', 'broccoli', 'cabbage', 'cantaloupe', 'cauliflower',
        'celery', 'chile_pepper', 'coffee', 'corn', 'cranberry', 'cucumber', 'currant',
        'eggplant', 'elderberry', 'garlic', 'ginger', 'grape', 'greenbean',
        'greenonion', 'honeydew', 'hops', 'kale', 'kiwi', 'leek', 'lettuce',
        'mustard', 'nectarine', 'oat', 'olive', 'onion', 'peanut', 'pepper',
        'pineapple', 'radish', 'raspberry', 'rhubarb', 'rice', 'rutabaga',
        'saguaro', 'soybean', 'spinach', 'squash', 'strawberry', 'sweetpotato',
        'tomatillo', 'tomato', 'turmeric', 'turnip', 'vanilla', 'yam', 'zucchini'
    ]

    // Guard against Croptopia items that don't exist (e.g. nectarine/vanilla
    // use different IDs) — suffix construction would otherwise emit market
    // recipes for nonexistent IDs that fail to register.
    croptopiaSeeds
        .filter(crop => Item.exists('croptopia:' + crop + '_seed'))
        .forEach(crop => {
            event.custom({
                type: 'farmingforblockheads:market',
                category: 'farmingforblockheads:seeds',
                preset: 'minecraft:seeds',
                result: { count: 1, item: 'croptopia:' + crop + '_seed' }
            })
        })

    // Croptopia saplings
    let croptopiaSaplings = [
        'almond', 'apple', 'apricot', 'avocado', 'banana', 'cashew', 'cherry',
        'coconut', 'date', 'dragonfruit', 'fig', 'grapefruit', 'kumquat', 'lemon',
        'lime', 'mango', 'nutmeg', 'orange', 'peach', 'pear', 'pecan', 'persimmon',
        'plum', 'pomegranate', 'starfruit', 'walnut', 'cinnamon'
    ]

    croptopiaSaplings
        .filter(tree => Item.exists('croptopia:' + tree + '_sapling'))
        .forEach(tree => {
            event.custom({
                type: 'farmingforblockheads:market',
                category: 'farmingforblockheads:saplings',
                preset: 'minecraft:saplings',
                result: { count: 1, item: 'croptopia:' + tree + '_sapling' }
            })
        })
})
