package service

import (
	"apskel-pos-be/internal/models"
	"apskel-pos-be/internal/processor"
	"context"

	"github.com/google/uuid"
)

type ProductRecipeService interface {
	Create(ctx context.Context, organizationID uuid.UUID, req *models.CreateProductRecipeRequest) (*models.ProductRecipeResponse, error)
	GetByID(ctx context.Context, id uuid.UUID, organizationID uuid.UUID) (*models.ProductRecipeResponse, error)
	GetByProductID(ctx context.Context, productID uuid.UUID, organizationID uuid.UUID) ([]*models.ProductRecipeResponse, error)
	GetByProductAndVariantID(ctx context.Context, productID uuid.UUID, variantID *uuid.UUID, organizationID uuid.UUID) ([]*models.ProductRecipeResponse, error)
	GetByIngredientID(ctx context.Context, ingredientID uuid.UUID, organizationID uuid.UUID) ([]*models.ProductRecipeResponse, error)
	Update(ctx context.Context, id uuid.UUID, organizationID uuid.UUID, req *models.UpdateProductRecipeRequest) (*models.ProductRecipeResponse, error)
	Delete(ctx context.Context, id uuid.UUID, organizationID uuid.UUID) error
	BulkCreate(ctx context.Context, organizationID uuid.UUID, recipes []models.CreateProductRecipeRequest) ([]*models.ProductRecipeResponse, error)
}

type ProductRecipeServiceImpl struct {
	processor processor.ProductRecipeProcessor
}

func NewProductRecipeService(processor processor.ProductRecipeProcessor) *ProductRecipeServiceImpl {
	return &ProductRecipeServiceImpl{
		processor: processor,
	}
}

func (s *ProductRecipeServiceImpl) Create(ctx context.Context, organizationID uuid.UUID, req *models.CreateProductRecipeRequest) (*models.ProductRecipeResponse, error) {
	return s.processor.Create(ctx, req, organizationID)
}

func (s *ProductRecipeServiceImpl) GetByID(ctx context.Context, id uuid.UUID, organizationID uuid.UUID) (*models.ProductRecipeResponse, error) {
	return s.processor.GetByID(ctx, id, organizationID)
}

func (s *ProductRecipeServiceImpl) GetByProductID(ctx context.Context, productID uuid.UUID, organizationID uuid.UUID) ([]*models.ProductRecipeResponse, error) {
	return s.processor.GetByProductID(ctx, productID, organizationID)
}

func (s *ProductRecipeServiceImpl) GetByProductAndVariantID(ctx context.Context, productID uuid.UUID, variantID *uuid.UUID, organizationID uuid.UUID) ([]*models.ProductRecipeResponse, error) {
	return s.processor.GetByProductAndVariantID(ctx, productID, variantID, organizationID)
}

func (s *ProductRecipeServiceImpl) GetByIngredientID(ctx context.Context, ingredientID uuid.UUID, organizationID uuid.UUID) ([]*models.ProductRecipeResponse, error) {
	return s.processor.GetByIngredientID(ctx, ingredientID, organizationID)
}

func (s *ProductRecipeServiceImpl) Update(ctx context.Context, id uuid.UUID, organizationID uuid.UUID, req *models.UpdateProductRecipeRequest) (*models.ProductRecipeResponse, error) {
	return s.processor.Update(ctx, id, req, organizationID)
}

func (s *ProductRecipeServiceImpl) Delete(ctx context.Context, id uuid.UUID, organizationID uuid.UUID) error {
	return s.processor.Delete(ctx, id, organizationID)
}

func (s *ProductRecipeServiceImpl) BulkCreate(ctx context.Context, organizationID uuid.UUID, recipes []models.CreateProductRecipeRequest) ([]*models.ProductRecipeResponse, error) {
	return s.processor.BulkCreate(ctx, recipes, organizationID)
}
