package filestore

import (
	"io"
	"time"
)

// FileMetadata represents metadata for a stored file
type FileMetadata struct {
	Filename    string            `json:"filename"`
	ContentType string            `json:"content_type"`
	Size        int64             `json:"size"`
	UploadedBy  string            `json:"uploaded_by"`
	UploadedAt  time.Time         `json:"uploaded_at"`
	Category    string            `json:"category"`
	Tags        []string          `json:"tags,omitempty"`
	Description string            `json:"description,omitempty"`
	Extra       map[string]string `json:"extra,omitempty"`
}

// UploadOptions contains options for file upload
type UploadOptions struct {
	Filename    string
	ContentType string
	UploadedBy  string
	Category    string
	Tags        []string
	Description string
	Extra       map[string]string
	MaxSize     int64 // Maximum file size in bytes
}

// DownloadOptions contains options for file download
type DownloadOptions struct {
	FileID string
}

// FileInfo represents information about a stored file
type FileInfo struct {
	FileID      string                 `json:"file_id"`
	Filename    string                 `json:"filename"`
	ContentType string                 `json:"content_type"`
	Size        int64                  `json:"size"`
	UploadedBy  string                 `json:"uploaded_by"`
	UploadedAt  time.Time              `json:"uploaded_at"`
	Category    string                 `json:"category"`
	Tags        []string               `json:"tags,omitempty"`
	Description string                 `json:"description,omitempty"`
	Extra       map[string]string      `json:"extra,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

// FileStoreService defines the interface for file storage operations
type FileStoreService interface {
	// Upload stores a file and returns the file ID
	Upload(fileID, filename string, reader io.Reader, options UploadOptions) (string, error)

	// Download retrieves a file by ID
	Download(fileID string) (io.ReadCloser, *FileInfo, error)

	// Delete removes a file by ID
	Delete(fileID string) error

	// GetFileInfo retrieves metadata for a file
	GetFileInfo(fileID string) (*FileInfo, error)

	// ListFiles lists files by category with optional filtering
	ListFiles(category string, tags []string, limit int64, skip int64) ([]*FileInfo, int64, error)

	// Exists checks if a file exists
	Exists(fileID string) (bool, error)
}
