package com.mosquito.project.service;

import com.mosquito.project.persistence.entity.RewardJobEntity;
import com.mosquito.project.persistence.repository.RewardJobRepository;
import org.springframework.stereotype.Service;

@Service
public class DbRewardQueue implements RewardQueue {
    private final RewardJobRepository repository;
    public DbRewardQueue(RewardJobRepository repository) { this.repository = repository; }

    @Override
    public void enqueueReward(String trackingId, String externalUserId, String payloadJson) {
        RewardJobEntity job = new RewardJobEntity();
        job.setTrackingId(trackingId);
        job.setExternalUserId(externalUserId);
        job.setPayload(payloadJson);
        job.setStatus("pending");
        job.setRetryCount(0);
        job.setNextRunAt(java.time.OffsetDateTime.now(java.time.ZoneOffset.UTC));
        job.setCreatedAt(java.time.OffsetDateTime.now(java.time.ZoneOffset.UTC));
        job.setUpdatedAt(java.time.OffsetDateTime.now(java.time.ZoneOffset.UTC));
        repository.save(job);
    }
}

