package mkt_active

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

	"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 GetErpMktActiveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *GetErpMktActiveLogic) GetErpMktActive(r *http.Request) (*types.Response, error) {
	// todo: add your logic here and delete this line
	r.ParseForm()
	schIdStr := r.Form.Get("sch_id")
	schId, err := strconv.ParseUint(schIdStr, 10, 64)
	if err != nil {
		logx.Error(err.Error())
		return &types.Response{500, err.Error(), nil}, nil
	}
	resp, err := l.svcCtx.Transformer.GetErpActive(l.ctx, &transform.GetErpActiveReq{SchId: schId})
	if err != nil {
		logx.Error(err.Error())
		return &types.Response{500, err.Error(), nil}, nil
	}
	return &types.Response{200, "", resp}, nil
}
