package models

import (
	"time"

	"github.com/google/uuid"
)

// IngredientUnitConverter represents the unit converter for ingredients
type IngredientUnitConverter struct {
	ID               uuid.UUID
	OrganizationID   uuid.UUID
	IngredientID     uuid.UUID
	FromUnitID       uuid.UUID
	ToUnitID         uuid.UUID
	ConversionFactor float64
	IsActive         bool
	CreatedAt        time.Time
	UpdatedAt        time.Time
	CreatedBy        uuid.UUID
	UpdatedBy        uuid.UUID

	// Related entities
	Ingredient *Ingredient
	FromUnit   *Unit
	ToUnit     *Unit
}

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

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

type ListIngredientUnitConvertersRequest struct {
	IngredientID *uuid.UUID
	FromUnitID   *uuid.UUID
	ToUnitID     *uuid.UUID
	IsActive     *bool
	Search       string
	Page         int `validate:"required,min=1"`
	Limit        int `validate:"required,min=1,max=100"`
}

type ConvertUnitRequest struct {
	IngredientID uuid.UUID `validate:"required"`
	FromUnitID   uuid.UUID `validate:"required"`
	ToUnitID     uuid.UUID `validate:"required"`
	Quantity     float64   `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"`
}

