package logic

import (
	"context"
	"git.i2edu.net/i2/i2-bill-erp/transform"

	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/types"

	"git.i2edu.net/i2/go-zero/core/logx"
)

type GetErpCityTreeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetErpCityTreeLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetErpCityTreeLogic {
	return GetErpCityTreeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetErpCityTreeLogic) GetErpCityTree() (*types.Response, error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.GetErpCity()
	if err != nil {
		logx.Error(err.Error())
		return &types.Response{500, err.Error(), nil}, nil
	}
	return &types.Response{200, "", transform.TreeNodes{Nodes: res}}, nil
}
