package com.example.todolist.config;

import javax.servlet.http.HttpSession;
import org.hibernate.envers.RevisionListener;
import org.springframework.context.annotation.Configuration;
import com.example.todolist.entity.TodoRevInfo;

import lombok.RequiredArgsConstructor;

@Configuration // ①
@RequiredArgsConstructor
public class TodoRevInfoListener implements RevisionListener { // ②
	private final HttpSession session;

	@Override
	public void newRevision(Object revisionEntity) { // ③
		TodoRevInfo todoRevInfo = (TodoRevInfo) revisionEntity; // ④
		Integer accountId = (Integer) session.getAttribute("accountId"); // ⑤
		if (accountId == null) {
			todoRevInfo.setOpId(null);
		} else {
			todoRevInfo.setOpId("" + accountId); // ⑥
		}
	}
}