package activity

import (
	"context"
	v1 "server/api/activity/v1"
	"server/internal/model"
	"server/internal/service"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

func (c *ControllerV1) SignIn(ctx context.Context, req *v1.SignInReq) (res *v1.SignInRes, err error) {
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	in := &model.UserSignInLogSignIn{
		UserId:         userId,
		RuleId:         req.RuleId,
		RewardDetailId: req.RewardDetailId,
		SignInDate:     gtime.Now(), // 或根据 req.SignInDate 解析
	}
	out, err := service.UserSignInLogs().Sign(ctx, in)
	if err != nil {
		return nil, err
	}
	return &v1.SignInRes{Success: out.Success}, nil
}
