// Path: src/main/java/com/membaza/api/users/service/date/DateService.java
// public interface DateService {
// 
//     Instant instantNow();
// 
//     Date now();
// 
//     Clock clock();
// 
// }
// 
// Path: src/main/java/com/membaza/api/users/persistence/User.java
// @Data
// @Document(collection = "users")
// public final class User {
// 
//     @Id
//     private String id;
// 
//     private @NotNull String firstname;
//     private @NotNull String lastname;
// 
//     @Indexed(unique=true)
//     private @NotNull String email;
//     private @NotNull String password;
//     private @NotNull Set<Role> roles;
//     private @NotNull Set<String> privileges;
//     private @NotNull Date dateRegistered;
//     private boolean confirmed;
//     private boolean enabled;
// 
//     @Indexed(unique=true)
//     private String userCreationCode;
//     private Set<EmailChange> emailChanges;
//     private Set<PasswordChange> passwordChanges;
//     private Set<UserDeletion> userDeletions;
// 
//     @JsonIgnore
//     public String getPassword(){
//         return password;
//     }
// 
//     @JsonIgnore
//     public String getUserCreationCode(){
//         return userCreationCode;
//     }
// }


import com.membaza.api.users.service.date.DateService;
import com.membaza.api.users.persistence.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Date;
import static java.time.temporal.ChronoUnit.WEEKS;
import static java.util.Objects.requireNonNull;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
package com.membaza.api.users.service.purge;




/**
 * @author Emil Forslund
 * @since  1.0.0
 */
@Service
@EnableScheduling
public final class TokensPurgeService {

    private static final Logger LOGGER =
        LoggerFactory.getLogger(TokensPurgeService.class);

    private final DateService dates;
    private final MongoTemplate mongo;
    private final Environment env;

    public TokensPurgeService(
            final DateService dates,
            final MongoTemplate mongo,
            final Environment env) {

        this.dates = requireNonNull(dates);
        this.mongo = requireNonNull(mongo);
        this.env   = requireNonNull(env);
    }

    @Scheduled(cron = "0 0 1 * * *") // Run every hour...
    public void purgeExpired() {
// Path: src/main/java/com/membaza/api/users/service/date/DateService.java
// public interface DateService {
// 
//     Instant instantNow();
// 
//     Date now();
// 
//     Clock clock();
// 
// }
// 
// Path: src/main/java/com/membaza/api/users/persistence/User.java
// @Data
// @Document(collection = "users")
// public final class User {
// 
//     @Id
//     private String id;
// 
//     private @NotNull String firstname;
//     private @NotNull String lastname;
// 
//     @Indexed(unique=true)
//     private @NotNull String email;
//     private @NotNull String password;
//     private @NotNull Set<Role> roles;
//     private @NotNull Set<String> privileges;
//     private @NotNull Date dateRegistered;
//     private boolean confirmed;
//     private boolean enabled;
// 
//     @Indexed(unique=true)
//     private String userCreationCode;
//     private Set<EmailChange> emailChanges;
//     private Set<PasswordChange> passwordChanges;
//     private Set<UserDeletion> userDeletions;
// 
//     @JsonIgnore
//     public String getPassword(){
//         return password;
//     }
// 
//     @JsonIgnore
//     public String getUserCreationCode(){
//         return userCreationCode;
//     }
// }


// Path: src/main/java/com/membaza/api/users/service/purge/TokensPurgeService.java
import com.membaza.api.users.service.date.DateService;
import com.membaza.api.users.persistence.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Date;
import static java.time.temporal.ChronoUnit.WEEKS;
import static java.util.Objects.requireNonNull;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;

package com.membaza.api.users.service.purge;




/**
 * @author Emil Forslund
 * @since  1.0.0
 */
@Service
@EnableScheduling
public final class TokensPurgeService {

    private static final Logger LOGGER =
        LoggerFactory.getLogger(TokensPurgeService.class);

    private final DateService dates;
    private final MongoTemplate mongo;
    private final Environment env;

    public TokensPurgeService(
            final DateService dates,
            final MongoTemplate mongo,
            final Environment env) {

        this.dates = requireNonNull(dates);
        this.mongo = requireNonNull(mongo);
        this.env   = requireNonNull(env);
    }

    @Scheduled(cron = "0 0 1 * * *") // Run every hour...
    public void purgeExpired() {
        if (!Boolean.parseBoolean(env.getProperty("service.purge.enabled"))) {