package cache

import (
	"sync"
)

// UnavailableOfferings tracks offerings that are currently unavailable
type UnavailableOfferings struct {
	mu       sync.RWMutex
	offerings map[string]struct{}
}

// NewUnavailableOfferings creates a new UnavailableOfferings cache
func NewUnavailableOfferings() *UnavailableOfferings {
	return &UnavailableOfferings{
		offerings: make(map[string]struct{}),
	}
}

// Add marks an offering as unavailable
func (u *UnavailableOfferings) Add(offering string) {
	u.mu.Lock()
	defer u.mu.Unlock()
	u.offerings[offering] = struct{}{}
}

// Remove marks an offering as available
func (u *UnavailableOfferings) Remove(offering string) {
	u.mu.Lock()
	defer u.mu.Unlock()
	delete(u.offerings, offering)
}

// Contains checks if an offering is marked as unavailable
func (u *UnavailableOfferings) Contains(offering string) bool {
	u.mu.RLock()
	defer u.mu.RUnlock()
	_, exists := u.offerings[offering]
	return exists
}
