package processor

import (
	"context"

	"apskel-pos-be/internal/entities"

	"github.com/google/uuid"
)

// Repository interfaces for processors
type ChartOfAccountTypeRepository interface {
	Create(ctx context.Context, chartOfAccountType *entities.ChartOfAccountType) error
	GetByID(ctx context.Context, id uuid.UUID) (*entities.ChartOfAccountType, error)
	GetByCode(ctx context.Context, code string) (*entities.ChartOfAccountType, error)
	Update(ctx context.Context, chartOfAccountType *entities.ChartOfAccountType) error
	Delete(ctx context.Context, id uuid.UUID) error
	List(ctx context.Context, filters map[string]interface{}, page, limit int) ([]*entities.ChartOfAccountType, int, error)
	GetActive(ctx context.Context) ([]*entities.ChartOfAccountType, error)
}

type ChartOfAccountRepository interface {
	Create(ctx context.Context, chartOfAccount *entities.ChartOfAccount) error
	GetByID(ctx context.Context, id uuid.UUID) (*entities.ChartOfAccount, error)
	Update(ctx context.Context, chartOfAccount *entities.ChartOfAccount) error
	Delete(ctx context.Context, id uuid.UUID) error
	List(ctx context.Context, req *entities.ChartOfAccount) ([]*entities.ChartOfAccount, int, error)
	GetByOrganization(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID) ([]*entities.ChartOfAccount, error)
	GetByType(ctx context.Context, organizationID uuid.UUID, chartOfAccountTypeID uuid.UUID, outletID *uuid.UUID) ([]*entities.ChartOfAccount, error)
	GetByCode(ctx context.Context, organizationID uuid.UUID, code string, outletID *uuid.UUID) (*entities.ChartOfAccount, error)
}

type AccountRepository interface {
	Create(ctx context.Context, account *entities.Account) error
	GetByID(ctx context.Context, id uuid.UUID) (*entities.Account, error)
	Update(ctx context.Context, account *entities.Account) error
	Delete(ctx context.Context, id uuid.UUID) error
	List(ctx context.Context, req *entities.Account) ([]*entities.Account, int, error)
	GetByOrganization(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID) ([]*entities.Account, error)
	GetByChartOfAccount(ctx context.Context, chartOfAccountID uuid.UUID) ([]*entities.Account, error)
	GetByNumber(ctx context.Context, organizationID uuid.UUID, number string, outletID *uuid.UUID) (*entities.Account, error)
	UpdateBalance(ctx context.Context, id uuid.UUID, amount float64) error
	GetBalance(ctx context.Context, id uuid.UUID) (float64, error)
}

type OrderIngredientTransactionRepository interface {
	Create(ctx context.Context, transaction *entities.OrderIngredientTransaction) error
	GetByID(ctx context.Context, id, organizationID uuid.UUID) (*entities.OrderIngredientTransaction, error)
	Update(ctx context.Context, transaction *entities.OrderIngredientTransaction) error
	Delete(ctx context.Context, id, organizationID uuid.UUID) error
	List(ctx context.Context, organizationID uuid.UUID, filters map[string]interface{}, page, limit int) ([]*entities.OrderIngredientTransaction, int64, error)
	GetByOrderID(ctx context.Context, orderID, organizationID uuid.UUID) ([]*entities.OrderIngredientTransaction, error)
	GetByOrderItemID(ctx context.Context, orderItemID, organizationID uuid.UUID) ([]*entities.OrderIngredientTransaction, error)
	GetByIngredientID(ctx context.Context, ingredientID, organizationID uuid.UUID) ([]*entities.OrderIngredientTransaction, error)
	GetSummary(ctx context.Context, organizationID uuid.UUID, filters map[string]interface{}) ([]*entities.OrderIngredientTransaction, error)
	BulkCreate(ctx context.Context, transactions []*entities.OrderIngredientTransaction) error
}

type ProductRecipeRepository interface {
	Create(ctx context.Context, productRecipe *entities.ProductRecipe) error
	GetByID(ctx context.Context, id, organizationID uuid.UUID) (*entities.ProductRecipe, error)
	GetByProductID(ctx context.Context, productID, organizationID uuid.UUID) ([]*entities.ProductRecipe, error)
	GetByIngredientID(ctx context.Context, ingredientID, organizationID uuid.UUID) ([]*entities.ProductRecipe, error)
	Update(ctx context.Context, productRecipe *entities.ProductRecipe) error
	Delete(ctx context.Context, id, organizationID uuid.UUID) error
	DeleteByProductID(ctx context.Context, productID, organizationID uuid.UUID) error
}

type IngredientRepository interface {
	Create(ctx context.Context, ingredient *entities.Ingredient) error
	GetByID(ctx context.Context, id, organizationID uuid.UUID) (*entities.Ingredient, error)
	GetAll(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string, isSemiFinished *bool) ([]*entities.Ingredient, int, error)
	Update(ctx context.Context, ingredient *entities.Ingredient) error
	Delete(ctx context.Context, id, organizationID uuid.UUID) error
	UpdateStock(ctx context.Context, id uuid.UUID, newStock float64, organizationID uuid.UUID) error
}

type UnitRepository interface {
	Create(ctx context.Context, unit *entities.Unit) error
	GetByID(ctx context.Context, id, organizationID uuid.UUID) (*entities.Unit, error)
	GetAll(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID, page, limit int, search string) ([]*entities.Unit, int, error)
	Update(ctx context.Context, unit *entities.Unit) error
	Delete(ctx context.Context, id, organizationID uuid.UUID) error
}
