package dev.drawethree.xprison.gangs.service.impl;

import dev.drawethree.xprison.XPrison;
import dev.drawethree.xprison.gangs.model.Gang;
import dev.drawethree.xprison.gangs.model.GangInvitation;
import dev.drawethree.xprison.gangs.repo.GangsRepository;
import dev.drawethree.xprison.gangs.service.GangsService;
import org.bukkit.Bukkit;

import java.util.List;

public class GangsServiceImpl implements GangsService {

	private final GangsRepository repository;

	public GangsServiceImpl(GangsRepository repository) {
		this.repository = repository;
	}

	@Override
	public void updateGang(Gang g) {
		repository.updateGang(g);
	}

	@Override
	public void deleteGang(Gang g) {
		repository.deleteGang(g);
	}

	@Override
	public void createGang(Gang g) {
		repository.createGang(g);
	}

	public void createGangAsync(Gang g) {
		Bukkit.getScheduler().runTaskAsynchronously(XPrison.getInstance(), () -> {
			try {
				createGang(g); // Call the synchronous createGang method
			} catch (Exception e) {
				XPrison.getInstance().getLogger().warning("Failed to create gang: " + e.getMessage());
			}
		});
	}

	public void deleteGangAsync(Gang g) {
		Bukkit.getScheduler().runTaskAsynchronously(XPrison.getInstance(), () -> {
			try {
				deleteGang(g); // Call the synchronous deleteGang method
			} catch (Exception e) {
				XPrison.getInstance().getLogger().warning("Failed to delete gang: " + e.getMessage());
			}
		});
	}

	@Override
	public List<Gang> getAllGangs() {
		return repository.getAllGangs();
	}

	@Override
	public List<GangInvitation> getGangInvitations(Gang gang) {
		return repository.getGangInvitations(gang);
	}

	@Override
	public void createGangInvitation(GangInvitation gangInvitation) {
		repository.createGangInvitation(gangInvitation);
	}

	@Override
	public void deleteGangInvitation(GangInvitation gangInvitation) {
		repository.deleteGangInvitation(gangInvitation);
	}
}





//package dev.drawethree.xprison.gangs.service.impl;
//
//import dev.drawethree.xprison.gangs.model.Gang;
//import dev.drawethree.xprison.gangs.model.GangInvitation;
//import dev.drawethree.xprison.gangs.repo.GangsRepository;
//import dev.drawethree.xprison.gangs.service.GangsService;
//
//import java.util.List;
//
//public class GangsServiceImpl implements GangsService {
//
//	private final GangsRepository repository;
//
//	public GangsServiceImpl(GangsRepository repository) {
//		this.repository = repository;
//	}
//
//	@Override
//	public void updateGang(Gang g) {
//		repository.updateGang(g);
//	}
//
//	@Override
//	public void deleteGang(Gang g) {
//		repository.deleteGang(g);
//	}
//
//	@Override
//	public void createGang(Gang g) {
//		repository.createGang(g);
//	}
//
//	@Override
//	public List<Gang> getAllGangs() {
//		return repository.getAllGangs();
//	}
//
//	@Override
//	public List<GangInvitation> getGangInvitations(Gang gang) {
//		return repository.getGangInvitations(gang);
//	}
//
//	@Override
//	public void createGangInvitation(GangInvitation gangInvitation) {
//		repository.createGangInvitation(gangInvitation);
//	}
//
//	@Override
//	public void deleteGangInvitation(GangInvitation gangInvitation) {
//		repository.deleteGangInvitation(gangInvitation);
//	}
//}
