package svc

import (
	"context"
	"errors"

	"golib/v1/features/mlib/mo"
)

var (
	ErrClientDisconnect = errors.New("ErrClientDisconnect")
)

var (
	mongoDB   mo.Handler
	isConnect bool
)

func Start(uri string) (err error) {
	mongoDB, err = mo.NewMongoClient(uri)
	return err
}

func Handler() mo.Handler {
	if isConnect {
		panic(ErrClientDisconnect)
	}
	return mongoDB
}

func DefaultCtx() (context.Context, context.CancelFunc) {
	return context.WithTimeout(context.Background(), mo.DefaultTimout)
}
