package logic

import (
	"context"
	"errors"

	"juwan-backend/app/order/rpc/internal/models"
	"juwan-backend/app/order/rpc/internal/svc"
	"juwan-backend/app/order/rpc/pb"

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

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

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

func (l *DelOrderStateLogsLogic) DelOrderStateLogs(in *pb.DelOrderStateLogsReq) (*pb.DelOrderStateLogsResp, error) {
	if err := l.svcCtx.OrderModelsRW.OrderStateLogs.DeleteOneID(in.Id).Exec(l.ctx); err != nil {
		if models.IsNotFound(err) {
			return nil, errors.New("order state log not found")
		}
		return nil, err
	}

	return &pb.DelOrderStateLogsResp{}, nil
}
