package ru.ulstu.paper.service;

import org.springframework.stereotype.Service;
import ru.ulstu.core.util.DateUtils;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.strategy.api.EntityCreateStrategy;
import ru.ulstu.user.model.User;

import java.util.Date;
import java.util.List;

@Service
public class PaperCreateStrategy extends EntityCreateStrategy<Paper> {
    private static final String DEFAULT_NAME = "Статья создана автоматически, т.к. у вас не найдено статей";
    private static final int DEFAULT_DEADLINE_DAYS = 14;
    private final PaperService paperService;

    public PaperCreateStrategy(PaperService paperService) {
        this.paperService = paperService;
    }

    @Override
    protected List<Paper> getActiveEntities() {
        return paperService.findAll();
    }

    @Override
    protected void createEntity(User user) {
        paperService.create(DEFAULT_NAME, user, DateUtils.addDays(new Date(), DEFAULT_DEADLINE_DAYS));
    }
}
