package data

import (
	"sync"

	"quantex.com/qfixdpl/src/domain"
)

type InMemoryOrderStore struct {
	mu     sync.RWMutex
	orders []domain.Order
}

func NewOrderStore() *InMemoryOrderStore {
	return &InMemoryOrderStore{}
}

func (s *InMemoryOrderStore) SaveOrder(order domain.Order) {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.orders = append(s.orders, order)
}

func (s *InMemoryOrderStore) GetOrders() []domain.Order {
	s.mu.RLock()
	defer s.mu.RUnlock()
	result := make([]domain.Order, len(s.orders))
	copy(result, s.orders)
	return result
}

func (s *InMemoryOrderStore) GetOrderByClOrdID(id string) (domain.Order, bool) {
	s.mu.RLock()
	defer s.mu.RUnlock()
	for _, o := range s.orders {
		if o.ClOrdID == id {
			return o, true
		}
	}
	return domain.Order{}, false
}
