package org.ntlab.citrusserver.repositories;
import org.ntlab.citrusserver.entities.Account;
import org.ntlab.citrusserver.entities.Book;
import org.ntlab.citrusserver.entities.Schedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.Set;
@Repository
public class ScheduleManager {
private final AccountManager accountManager; //仮
private final HashMap<String, Integer> nextScheduleId = new HashMap<>();
@Autowired
public ScheduleManager(AccountManager accountManager) {
this.accountManager = accountManager;
}
//管理
private final HashMap<String, //accountId
HashMap<Integer, //year
HashMap<Integer, //month
HashMap<Integer, //day
HashMap<Integer, //scheduleId
Schedule>>>>> schedules
= new HashMap<>();
public HashMap<Integer,HashMap<Integer,HashMap<Integer,HashMap<Integer,Schedule>>>> getScheduleAll(String accountId) {
return schedules.get(accountId);
}
public HashMap<Integer,HashMap<Integer,HashMap<Integer,Schedule>>> getScheduleYear(String accountId, int year){
return schedules.get(accountId).get(year);
}
public HashMap<Integer,HashMap<Integer,Schedule>> getScheduleMonth(String accountId, int year, int month){
return schedules.get(accountId).get(year).get(month);
}
public HashMap<Integer,Schedule> getScheduleDay(String accountId, int year, int month, int day){
return schedules.get(accountId).get(year).get(month).get(day);
}
public Schedule addSchedule(String accountId, int year, int month, int day, String title, String startTime, String endTime, Integer bookId){
if(bookId == null)bookId = 0;
if(!schedules.containsKey(accountId)){
schedules.put(accountId, new HashMap<>());
}
if(!schedules.get(accountId).containsKey(year)){
schedules.get(accountId).put(year, new HashMap<>());
}
if(!schedules.get(accountId).get(year).containsKey(month)){
schedules.get(accountId).get(year).put(month, new HashMap<>());
}
if(!schedules.get(accountId).get(year).get(month).containsKey(day)){
schedules.get(accountId).get(year).get(month).put(day, new HashMap<>());
}
String accountSchedule = accountId + year + month + day;//
if(!nextScheduleId.containsKey(accountSchedule)){
nextScheduleId.put(accountSchedule, 0);
}
int newScheduleId = nextScheduleId.get(accountSchedule);
Schedule newSchedule = new Schedule(title, startTime, endTime, bookId, newScheduleId);
schedules.get(accountId).get(year).get(month).get(day).put(newScheduleId, newSchedule);
nextScheduleId.put(accountSchedule, newScheduleId + 1);
return newSchedule;
}
public Schedule getScheduleId(String accountId, int year, int month, int day, int scheduleId){
return schedules.get(accountId).get(year).get(month).get(day).get(scheduleId);
}
public void deleteSchedule(String accountId, int year, int month, int day, int scheduleId){
schedules.get(accountId).get(year).get(month).get(day).remove(scheduleId);
}
public void setScheduleStartTime(String accountId, int year, int month, int day, int scheduleId, String newTime){
schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setStartTime(newTime);
}
public void setScheduleEndTime(String accountId, int year, int month, int day, int scheduleId, String newTime){
schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setEndTime(newTime);
}
public void changeScheduleTitle(String accountId, int year, int month, int day, int scheduleId, String newTitle){
schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setTitle(newTitle);
}
public void setSchedulesBookId(String accountId, int year, int month, int day, int scheduleId, Integer newBookId){
if(newBookId == null)newBookId = 0;
schedules.get(accountId).get(year).get(month).get(day).get(scheduleId).setBookId(newBookId);
}
}