package contract

import (
	"time"

	"github.com/google/uuid"
)

// Request structures
type CreateProductRecipeRequest struct {
	OutletID        *uuid.UUID `json:"outlet_id"`
	ProductID       uuid.UUID  `json:"product_id" validate:"required"`
	VariantID       *uuid.UUID `json:"variant_id"`
	IngredientID    uuid.UUID  `json:"ingredient_id" validate:"required"`
	Quantity        float64    `json:"quantity" validate:"required,gt=0"`
	WastePercentage float64    `json:"waste_percentage" validate:"min=0,max=100"`
}

type UpdateProductRecipeRequest struct {
	OutletID        *uuid.UUID `json:"outlet_id"`
	VariantID       *uuid.UUID `json:"variant_id"`
	Quantity        float64    `json:"quantity" validate:"required,gt=0"`
	WastePercentage float64    `json:"waste_percentage" validate:"min=0,max=100"`
}

type GetProductRecipeByProductIDRequest struct {
	ProductID uuid.UUID  `json:"-"`
	VariantID *uuid.UUID `json:"-"`
}

type BulkCreateProductRecipeRequest struct {
	Recipes []CreateProductRecipeRequest `json:"recipes" validate:"required,min=1"`
}

// Response structures
type ProductRecipeResponse struct {
	ID              uuid.UUID                      `json:"id"`
	OrganizationID  uuid.UUID                      `json:"organization_id"`
	OutletID        *uuid.UUID                     `json:"outlet_id"`
	ProductID       uuid.UUID                      `json:"product_id"`
	VariantID       *uuid.UUID                     `json:"variant_id"`
	IngredientID    uuid.UUID                      `json:"ingredient_id"`
	Quantity        float64                        `json:"quantity"`
	WastePercentage float64                        `json:"waste_percentage"`
	CreatedAt       time.Time                      `json:"created_at"`
	UpdatedAt       time.Time                      `json:"updated_at"`
	Product         *ProductResponse               `json:"product,omitempty"`
	ProductVariant  *ProductVariantResponse        `json:"product_variant,omitempty"`
	Ingredient      *ProductRecipeIngredientResponse `json:"ingredient,omitempty"`
}

type ProductRecipeIngredientResponse struct {
	ID             uuid.UUID                 `json:"id"`
	OrganizationID uuid.UUID                 `json:"organization_id"`
	OutletID       *uuid.UUID                `json:"outlet_id"`
	Name           string                    `json:"name"`
	UnitID         uuid.UUID                 `json:"unit_id"`
	Cost           float64                   `json:"cost"`
	Stock          float64                   `json:"stock"`
	IsSemiFinished bool                      `json:"is_semi_finished"`
	IsActive       bool                      `json:"is_active"`
	Metadata       map[string]interface{}    `json:"metadata"`
	CreatedAt      time.Time                 `json:"created_at"`
	UpdatedAt      time.Time                 `json:"updated_at"`
	Unit           *ProductRecipeUnitResponse `json:"unit,omitempty"`
}

type ProductRecipeUnitResponse struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Symbol    string    `json:"symbol"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}