package com.alterdekim.game.service;

import com.alterdekim.game.entity.PhoneMessage;
import com.alterdekim.game.entity.Postcard;
import com.alterdekim.game.repository.PhoneMessageRepository;
import com.alterdekim.game.repository.PostcardRepository;
import lombok.AllArgsConstructor;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class PostcardService {
    private final PostcardRepository repository;

    public List<Postcard> getAllPostcards() {
        return repository.findAll();
    }

    public List<Postcard> getAllPostcardsOfUser(Integer userId) {
        return this.repository.findByReceiverId(userId);
    }

    public void markAsRead(Long messageId) {
        this.repository.markAsRead(messageId);
    }

    public Postcard getPostcardById(long id) {
        return repository.findById(id).orElse(null);
    }

    public void removeById(long id) {
        repository.deleteById(id);
    }

    public void savePostcard(Postcard postcard) {
        repository.save(postcard);
    }
}
