package contract

import (
	"time"

	"github.com/google/uuid"
)

// Request DTOs
type CreateIngredientUnitConverterRequest struct {
	IngredientID     uuid.UUID `json:"ingredient_id" validate:"required"`
	FromUnitID       uuid.UUID `json:"from_unit_id" validate:"required"`
	ToUnitID         uuid.UUID `json:"to_unit_id" validate:"required"`
	ConversionFactor float64   `json:"conversion_factor" validate:"required,gt=0"`
	IsActive         *bool     `json:"is_active,omitempty" validate:"omitempty"`
}

type UpdateIngredientUnitConverterRequest struct {
	FromUnitID       *uuid.UUID `json:"from_unit_id,omitempty" validate:"omitempty"`
	ToUnitID         *uuid.UUID `json:"to_unit_id,omitempty" validate:"omitempty"`
	ConversionFactor *float64   `json:"conversion_factor,omitempty" validate:"omitempty,gt=0"`
	IsActive         *bool      `json:"is_active,omitempty" validate:"omitempty"`
}

type ListIngredientUnitConvertersRequest struct {
	IngredientID *uuid.UUID `json:"ingredient_id,omitempty"`
	FromUnitID   *uuid.UUID `json:"from_unit_id,omitempty"`
	ToUnitID     *uuid.UUID `json:"to_unit_id,omitempty"`
	IsActive     *bool      `json:"is_active,omitempty"`
	Search       string     `json:"search,omitempty"`
	Page         int        `json:"page" validate:"required,min=1"`
	Limit        int        `json:"limit" validate:"required,min=1,max=100"`
}

type ConvertUnitRequest struct {
	IngredientID uuid.UUID `json:"ingredient_id" validate:"required"`
	FromUnitID   uuid.UUID `json:"from_unit_id" validate:"required"`
	ToUnitID     uuid.UUID `json:"to_unit_id" validate:"required"`
	Quantity     float64   `json:"quantity" validate:"required,gt=0"`
}

// Response DTOs
type IngredientUnitConverterResponse struct {
	ID               uuid.UUID           `json:"id"`
	OrganizationID   uuid.UUID           `json:"organization_id"`
	IngredientID     uuid.UUID           `json:"ingredient_id"`
	FromUnitID       uuid.UUID           `json:"from_unit_id"`
	ToUnitID         uuid.UUID           `json:"to_unit_id"`
	ConversionFactor float64             `json:"conversion_factor"`
	IsActive         bool                `json:"is_active"`
	CreatedAt        time.Time           `json:"created_at"`
	UpdatedAt        time.Time           `json:"updated_at"`
	CreatedBy        uuid.UUID           `json:"created_by"`
	UpdatedBy        uuid.UUID           `json:"updated_by"`
	Ingredient       *IngredientResponse `json:"ingredient,omitempty"`
	FromUnit         *UnitResponse       `json:"from_unit,omitempty"`
	ToUnit           *UnitResponse       `json:"to_unit,omitempty"`
}

type ConvertUnitResponse struct {
	FromQuantity     float64             `json:"from_quantity"`
	FromUnit         *UnitResponse       `json:"from_unit"`
	ToQuantity       float64             `json:"to_quantity"`
	ToUnit           *UnitResponse       `json:"to_unit"`
	ConversionFactor float64             `json:"conversion_factor"`
	Ingredient       *IngredientResponse `json:"ingredient,omitempty"`
}

type ListIngredientUnitConvertersResponse struct {
	Converters []IngredientUnitConverterResponse `json:"converters"`
	TotalCount int                               `json:"total_count"`
	Page       int                               `json:"page"`
	Limit      int                               `json:"limit"`
	TotalPages int                               `json:"total_pages"`
}

