package svc

import (
	"backend/internal/config"
	"backend/internal/middleware"
	"backend/pkg/library/errs"
	"backend/pkg/library/errs/code"
	vi "backend/pkg/library/validator"
	memberUC "backend/pkg/member/domain/usecase"
	tokenUC "backend/pkg/permission/domain/usecase"

	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/rest"
)

type ServiceContext struct {
	Config         config.Config
	AuthMiddleware rest.Middleware
	AccountUC      memberUC.AccountUseCase
	Validate       vi.Validate
	TokenUC        tokenUC.TokenUseCase
}

func NewServiceContext(c config.Config) *ServiceContext {
	rds, err := redis.NewRedis(c.RedisConf)
	if err != nil {
		panic(err)
	}
	errs.Scope = code.CloudEPPortalGW

	return &ServiceContext{
		Config:         c,
		AuthMiddleware: middleware.NewAuthMiddleware().Handle,
		AccountUC:      NewAccountUC(&c, rds),
		Validate:       vi.MustValidator(),
		TokenUC:        NewTokenUC(&c, rds),
	}
}
