package datastore

import (
	"awesome-back/internal/domain/entities"
	"awesome-back/internal/domain/repositories"
	"awesome-back/pkg/errors"
)

type MockPastryRepository struct {
	pastries []entities.Pastry
}

func NewMockPastryRepository() repositories.PastryRepository {
	return &MockPastryRepository{
		pastries: []entities.Pastry{
			{ID: 1, Name: "Круассан", Description: "Слоеная выпечка с маслом", Price: 80.0, Category: "Выпечка"},
			{ID: 2, Name: "Тирамису", Description: "Итальянский десерт", Price: 150.0, Category: "Десерты"},
			{ID: 3, Name: "Чизкейк", Description: "Сырный торт", Price: 130.0, Category: "Десерты"},
			{ID: 4, Name: "Маффин", Description: "Шоколадный кекс", Price: 70.0, Category: "Выпечка"},
			{ID: 5, Name: "Печенье", Description: "Домашнее овсяное печенье", Price: 50.0, Category: "Печенье"},
		},
	}
}

func (r *MockPastryRepository) FindAll() ([]entities.Pastry, error) {
	return r.pastries, nil
}

func (r *MockPastryRepository) FindByID(id int) (*entities.Pastry, error) {
	for _, pastry := range r.pastries {
		if pastry.ID == id {
			return &pastry, nil
		}
	}
	return nil, errors.NewNotFoundError("pastry not found")
}

func (r *MockPastryRepository) FindByCategory(category string) ([]entities.Pastry, error) {
	var filtered []entities.Pastry
	for _, pastry := range r.pastries {
		if pastry.Category == category {
			filtered = append(filtered, pastry)
		}
	}

	if len(filtered) == 0 {
		return nil, errors.NewNotFoundError("no pastries found for category")
	}

	return filtered, nil
}
