package setting

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type GetSettingLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSettingLogic {
	return &GetSettingLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *GetSettingLogic) GetSetting(req *types.SettingKeyPath) (*types.SettingData, error) {
	item, err := l.svcCtx.Setting.Get(l.ctx, req.Scope, req.ScopeID, req.Key)
	if err != nil {
		return nil, err
	}
	data := toSettingData(item)
	return &data, nil
}
