package file_service

import (
	"context"
	"evening_detective_server/internal/modules/file_storage"
	"evening_detective_server/internal/modules/string_tools"
)

type FileService struct {
	fileStorage file_storage.IFileStorage
}

func NewFileService(
	fileStorage file_storage.IFileStorage,
) *FileService {
	return &FileService{
		fileStorage: fileStorage,
	}
}

func (s *FileService) UploadFile(
	ctx context.Context,
	file *file_storage.File,
) (string, error) {
	file.Name = string_tools.Transliterate(file.Name)
	if err := s.fileStorage.Put(ctx, file); err != nil {
		return "", err
	}
	return file.Name, nil
}

func (s *FileService) DownloadFile(
	ctx context.Context,
	filename string,
) (*file_storage.File, error) {
	file, err := s.fileStorage.Get(ctx, filename)
	if err != nil {
		return nil, err
	}
	return file, nil
}
