package admin_agent

import (
	"context"

	"ycc-server/app/main/api/internal/svc"
	"ycc-server/app/main/api/internal/types"

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

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

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

func (l *AdminUpdateAgentProductionConfigLogic) AdminUpdateAgentProductionConfig(req *types.AdminUpdateAgentProductionConfigReq) (resp *types.AdminUpdateAgentProductionConfigResp, err error) {
	cfg, err := l.svcCtx.AgentProductConfigModel.FindOne(l.ctx, req.Id)
	if err != nil {
		return nil, err
	}
	cfg.CostPrice = req.CostPrice
	cfg.PriceRangeMin = req.PriceRangeMin
	cfg.PriceRangeMax = req.PriceRangeMax
	cfg.PricingStandard = req.PricingStandard
	cfg.OverpricingRatio = req.OverpricingRatio
	_, err = l.svcCtx.AgentProductConfigModel.Update(l.ctx, nil, cfg)
	if err != nil {
		return nil, err
	}
	resp = &types.AdminUpdateAgentProductionConfigResp{Success: true}
	return
}
