package agent

import (
	"context"

	"tydata-server/app/main/api/internal/svc"
	"tydata-server/app/main/api/internal/types"
	"tydata-server/common/ctxdata"
	"tydata-server/common/xerr"

	"github.com/pkg/errors"
	"github.com/zeromicro/go-zero/core/logx"
)

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

func NewGetAgentWithdrawalTaxExemptionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentWithdrawalTaxExemptionLogic {
	return &GetAgentWithdrawalTaxExemptionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetAgentWithdrawalTaxExemptionLogic) GetAgentWithdrawalTaxExemption(req *types.GetWithdrawalTaxExemptionReq) (resp *types.GetWithdrawalTaxExemptionResp, err error) {
	_, err = ctxdata.GetUidFromCtx(l.ctx)
	if err != nil {
		return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %+v", err)
	}

	// 统一按6%收取税收，不再有免税额度
	return &types.GetWithdrawalTaxExemptionResp{
		TotalExemptionAmount:     0.00, // 免税总额度为0
		UsedExemptionAmount:      0.00, // 已使用免税额度为0
		RemainingExemptionAmount: 0.00, // 剩余免税额度为0
		TaxRate:                  l.svcCtx.Config.TaxConfig.TaxRate, // 6%税收
	}, nil
}
