package conversation

import (
	"context"
	"errors"
)

// ErrNotFound istenen konuşma ya da mesaj yoksa döner.
var ErrNotFound = errors.New("conversation: bulunamadı")

// Repository kalıcı depolama sözleşmesidir. Uygulamalar: MongoDB (storage) ve bellek içi (MemoryRepo).
type Repository interface {
	CreateConversation(ctx context.Context, c *Conversation) error
	// GetConversation yoksa ErrNotFound döner. Messages alanı doldurulmaz.
	GetConversation(ctx context.Context, id string) (*Conversation, error)
	// ListConversations kullanıcının konuşmalarını UpdatedAt'e göre yeniden eskiye sıralar.
	ListConversations(ctx context.Context, userID string, limit, offset int) ([]Conversation, error)
	UpdateTitle(ctx context.Context, id, title string) error
	// DeleteConversation konuşmayı ve tüm mesajlarını siler; yoksa ErrNotFound.
	DeleteConversation(ctx context.Context, id string) error
	// AppendMessage mesajı ekler ve konuşmanın UpdatedAt değerini günceller; konuşma yoksa ErrNotFound.
	AppendMessage(ctx context.Context, m *Message) error
	// Messages konuşmanın SON limit mesajını eskiden yeniye sıralı döndürür (limit<=0: hepsi).
	Messages(ctx context.Context, conversationID string, limit int) ([]Message, error)
	// ResolveToolConfirm konuşmadaki, HÂLÂ "pending" olan onay kartını kapatır.
	// Kart yoksa ya da zaten kapanmışsa ErrNotFound döner (ikinci çözüm ilkini ezmez).
	ResolveToolConfirm(ctx context.Context, conversationID, confirmID string, r ToolConfirmResolution) error
}
