package initialize

import (
	"context"
	"gitea.pena/PenaSide/heruvym/internal/repository/minio"
	"gitea.pena/PenaSide/heruvym/internal/repository/mongo"
	"gitea.pena/PenaSide/hlog"
	minioClient "github.com/minio/minio-go/v7"
	mongoDatabase "go.mongodb.org/mongo-driver/mongo"
)

type DepsRepositories struct {
	MinioClient   *minioClient.Client
	MongoDatabase *mongoDatabase.Database
	Cfg           Config
	HLogger       hlog.Logger
}

type Repositories struct {
	Minio *minio.BlobStore
	Mongo *mongo.DAL
}

func NewRepositories(ctx context.Context, deps DepsRepositories) (*Repositories, error) {
	minioRepo, err := minio.New(ctx, minio.Deps{
		HLogger: deps.HLogger,
		Store:   deps.MinioClient,
	})
	if err != nil {
		return nil, err
	}

	mongoRepo, err := mongo.New(ctx, mongo.DepsDAL{
		MongoDatabase: deps.MongoDatabase,
		HLogger:       deps.HLogger,
	})
	if err != nil {
		return nil, err
	}

	return &Repositories{
		Minio: minioRepo,
		Mongo: mongoRepo,
	}, nil
}
