package contract

import (
	"time"

	"github.com/google/uuid"
)

type CreateTableRequest struct {
	OutletID  uuid.UUID              `json:"outlet_id" validate:"required"`
	TableName string                 `json:"table_name" validate:"required,max=100"`
	PositionX float64                `json:"position_x" validate:"required"`
	PositionY float64                `json:"position_y" validate:"required"`
	Capacity  int                    `json:"capacity" validate:"required,min=1,max=20"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

type UpdateTableRequest struct {
	TableName *string                `json:"table_name,omitempty" validate:"omitempty,max=100"`
	Status    *string                `json:"status,omitempty" validate:"omitempty,oneof=available occupied reserved cleaning maintenance"`
	PositionX *float64               `json:"position_x,omitempty"`
	PositionY *float64               `json:"position_y,omitempty"`
	Capacity  *int                   `json:"capacity,omitempty" validate:"omitempty,min=1,max=20"`
	IsActive  *bool                  `json:"is_active,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

type OccupyTableRequest struct {
	OrderID   uuid.UUID `json:"order_id" validate:"required"`
	StartTime time.Time `json:"start_time" validate:"required"`
}

type ReleaseTableRequest struct {
	PaymentAmount float64 `json:"payment_amount" validate:"required,min=0"`
}

type TableResponse struct {
	ID             uuid.UUID              `json:"id"`
	OrganizationID uuid.UUID              `json:"organization_id"`
	OutletID       uuid.UUID              `json:"outlet_id"`
	TableName      string                 `json:"table_name"`
	StartTime      *time.Time             `json:"start_time,omitempty"`
	Status         string                 `json:"status"`
	OrderID        *uuid.UUID             `json:"order_id,omitempty"`
	PaymentAmount  float64                `json:"payment_amount"`
	PositionX      float64                `json:"position_x"`
	PositionY      float64                `json:"position_y"`
	Capacity       int                    `json:"capacity"`
	IsActive       bool                   `json:"is_active"`
	Metadata       map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt      time.Time              `json:"created_at"`
	UpdatedAt      time.Time              `json:"updated_at"`
	Order          *OrderResponse         `json:"order,omitempty"`
}

type ListTablesQuery struct {
	OrganizationID string `form:"organization_id"`
	OutletID       string `form:"outlet_id"`
	Status         string `form:"status"`
	IsActive       string `form:"is_active"`
	Search         string `form:"search"`
	Page           int    `form:"page,default=1"`
	Limit          int    `form:"limit,default=10"`
}

type ListTablesRequest struct {
	Page           int        `json:"page" validate:"min=1"`
	Limit          int        `json:"limit" validate:"min=1,max=100"`
	OrganizationID *uuid.UUID `json:"organization_id,omitempty"`
	OutletID       *uuid.UUID `json:"outlet_id,omitempty"`
	Status         *string    `json:"status,omitempty" validate:"omitempty,oneof=available occupied reserved cleaning maintenance"`
	IsActive       *bool      `json:"is_active,omitempty"`
	Search         string     `json:"search,omitempty"`
}

type ListTablesResponse struct {
	Tables     []TableResponse `json:"tables"`
	TotalCount int             `json:"total_count"`
	Page       int             `json:"page"`
	Limit      int             `json:"limit"`
	TotalPages int             `json:"total_pages"`
}
