// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
//     @Id
//     private String id;
// 
//     private long seq;
// 
// }
// 
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
// 
//     public SequenceException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
//     void save(SequenceId sequenceId);
// 
//     long getNextSequenceId(String key);
// }


import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.repositories.SequenceIdRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
package com.edwise.completespring.repositories.impl;


@Repository
@Slf4j
public class SequenceIdRepositoryImpl implements SequenceIdRepository {

    @Autowired
    private MongoOperations mongoOperation;

    @Override
    public long getNextSequenceId(String key) {
        //get sequence id
        Query query = new Query(Criteria.where("_id").is(key));

        //increase sequence id by 1
        Update update = new Update();
        update.inc("seq", 1);

        //return new increased id
        FindAndModifyOptions options = new FindAndModifyOptions();
        options.returnNew(true);

// Path: src/main/java/com/edwise/completespring/entities/SequenceId.java
// @Document(collection = "sequences")
// @Setter @Getter
// @Accessors(chain = true)
// @ToString(doNotUseGetters = true)
// public class SequenceId {
//     @Id
//     private String id;
// 
//     private long seq;
// 
// }
// 
// Path: src/main/java/com/edwise/completespring/exceptions/SequenceException.java
// public class SequenceException extends RuntimeException {
// 
//     public SequenceException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: src/main/java/com/edwise/completespring/repositories/SequenceIdRepository.java
// public interface SequenceIdRepository {
//     void save(SequenceId sequenceId);
// 
//     long getNextSequenceId(String key);
// }


// Path: src/main/java/com/edwise/completespring/repositories/impl/SequenceIdRepositoryImpl.java
import com.edwise.completespring.entities.SequenceId;
import com.edwise.completespring.exceptions.SequenceException;
import com.edwise.completespring.repositories.SequenceIdRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

package com.edwise.completespring.repositories.impl;


@Repository
@Slf4j
public class SequenceIdRepositoryImpl implements SequenceIdRepository {

    @Autowired
    private MongoOperations mongoOperation;

    @Override
    public long getNextSequenceId(String key) {
        //get sequence id
        Query query = new Query(Criteria.where("_id").is(key));

        //increase sequence id by 1
        Update update = new Update();
        update.inc("seq", 1);

        //return new increased id
        FindAndModifyOptions options = new FindAndModifyOptions();
        options.returnNew(true);

        SequenceId seqId =