package main

import (
	"github.com/sirupsen/logrus"
)

// logRequest logs incoming chat requests and extracted info
func logRequest(req ChatRequest, keywords map[string]interface{}, candidates []Visit, bestID string, err error) {
	logrus.WithFields(logrus.Fields{
		"message":    req.Message,
		"keywords":   keywords,
		"candidates": getCandidateIDs(candidates),
		"bestID":     bestID,
		"err":        err,
	}).Info("Chat request trace")
}

func getCandidateIDs(candidates []Visit) []string {
	ids := make([]string, len(candidates))
	for i, c := range candidates {
		ids[i] = c.ID
	}
	return ids
}

// Procedure represents a single procedure for a visit
type Procedure struct {
	Name        string `yaml:"name" json:"name"`
	Price       int    `yaml:"price" json:"price"`
	DurationMin int    `yaml:"duration_minutes" json:"duration_minutes"`
	Note        string `yaml:"note" json:"note"`
}

// Visit represents a visit entry
type Visit struct {
	ID         string      `yaml:"id" json:"id"`
	Visit      string      `yaml:"visit" json:"visit"`
	Keywords   []string    `yaml:"keywords" json:"keywords"`
	Procedures []Procedure `yaml:"procedures" json:"procedures"`
	Notes      string      `yaml:"notes" json:"notes,omitempty"`
}

// ChatRequest represents the incoming chat message
type ChatRequest struct {
	Message string `json:"message"`
}

// ChatResponse represents the response to the frontend
type ChatResponse struct {
	Match         *string     `json:"match"`
	Procedures    []Procedure `json:"procedures,omitempty"`
	TotalPrice    int         `json:"total_price,omitempty"`
	TotalDuration int         `json:"total_duration,omitempty"`
	Notes         string      `json:"notes,omitempty"`
}
