package loging

import (
	"context"
	"log-server/model/log/request"
	"strconv"
)

type ResetOtherLog struct {
	logical LogicalLog
	Date    string
}

func (s *ResetOtherLog) SuccessLog(ctx context.Context, request request.AddLogRequest, date string) (err error) {
	if request.ScriptType == 1 {
		return
	}
	s.Date = date
	b, _ := s.logical.ExistsUuidCodeCache(ctx, s.Date, request.LogUuid, request.Coding, request.GameId)
	if b {
		return
	} else {
		_ = s.logical.SetUuidCodeCache(context.Background(), s.Date, request.LogUuid, request.Coding, request.GameId)
	}
	code := strconv.Itoa(request.Coding)
	err = s.logical.PartTypeLogSetNum(ctx, s.Date, request.GameId, code, OkStatus, request.TaskType)
	if err != nil {
		return
	}
	err = s.logical.NodeLogSetNum(ctx, s.Date, request.GameId, code, OkStatus, request.TaskType)
	return
}

func (s *ResetOtherLog) FailLog(ctx context.Context, request request.AddLogRequest, date string) (err error) {
	if request.ScriptType == 1 {
		return
	}
	s.Date = date
	b, _ := s.logical.ExistsUuidCodeCache(ctx, s.Date, request.LogUuid, request.Coding, request.GameId)
	if b {
		return
	} else {
		_ = s.logical.SetUuidCodeCache(context.Background(), s.Date, request.LogUuid, request.Coding, request.GameId)
	}
	code := strconv.Itoa(request.Coding)
	if code[5:] == "00" {
		err = s.logical.CodeLogSetNum(ctx, s.Date, request.GameId, code, NoLogStatus, request.TaskType)
		return
	}
	err = s.logical.PartTypeLogSetNum(ctx, s.Date, request.GameId, code, FailStatus, request.TaskType)
	if err != nil {
		return
	}
	err = s.logical.NodeLogSetNum(ctx, s.Date, request.GameId, code, FailStatus, request.TaskType)
	return
}

func (s *ResetOtherLog) NoLogStatusData(ctx context.Context, request request.AddLogRequest, date string) (err error) {
	s.Date = date
	code := strconv.Itoa(request.Coding)
	b, _ := s.logical.ExistsUuidCodeCache(ctx, s.Date, request.LogUuid, request.Coding, request.GameId)
	if b {
		return
	} else {
		_ = s.logical.SetUuidCodeCache(context.Background(), s.Date, request.LogUuid, request.Coding, request.GameId)
	}
	err = s.logical.CodeLogSetNum(ctx, s.Date, request.GameId, code, NoLogStatus, request.TaskType)
	return
}
