package project;

import java.awt.List;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Map;

public class Repository {
	
	
	ArrayList<Participant> participantList=new ArrayList<Participant>();
	ArrayList<Interests> interestList=new ArrayList<Interests>();
	ArrayList<Relationships> relationshipsList=new ArrayList<Relationships>();
	public Repository(){
		createInterests();
		createRelationships();
		createParticipants();
		
	}
	
	
	private  void createParticipants(){
		participantList.add(new Participant(1, 16, "Female", "Any other Asian background", "student", "barnet", "barnet", "Secondary School"));
		participantList.add(new Participant(2, 25, "Female", "Any other ethnic group", "Graduate Student", "USA", "Greece", "University(Undergraduate)"));
		participantList.add(new Participant(3, 44, "Male", "American", "Physical Therapist", "Virginia Beach", "St Louis", "University(Undergraduate)"));
		participantList.add(new Participant(4, 21, "Female", "Any other White Background", "Retail", "Australia", "Australia", "Secondary School"));
		participantList.add(new Participant(5, 37, "Male", "Any other White background", "doctor", "Athens", "Athens", "University(Postgraduate)"));
		participantList.add(new Participant(6, 49, "Male", "Any other Asian background", "99", "London", "India", "Other"));
		participantList.add(new Participant(7, 18, "Male", "British", "99", "Norwich", "London", "College/6th Form"));
		participantList.add(new Participant(8, 27, "Male", "Any other White background", "Student", "99", "99", "University(Postgraduate)"));
		participantList.add(new Participant(9, 18, "Female", "Irish", "Student", "London", "London", "College/6th Form"));
		participantList.add(new Participant(10, 19, "Female", "Indian", "Student", "London", "London", "College/6th Form"));
		participantList.add(new Participant(11, 18, "Male", "African", "Student", "Brighton", "Barnet", "College/6th Form"));
		participantList.add(new Participant(12, 46, "Female", "Any other White background", "Housewife", "Abroad", "Greece", "Secondary School"));
		participantList.add(new Participant(13, 24, "Female", "Any other White background", "Customer Service", "99", "99", "University(Graduate)"));
		participantList.add(new Participant(14, 45, "Female", "Any other White background", "Unemployed", "Athens", "Greece", "Other"));
		participantList.add(new Participant(15, 24, "Female", "Any other White background", "Teacher ", "Greece ", "Greece", "University(Undergraduate)"));
		for (Participant p :participantList){
			Interests i=this.getInterests(p.getId());
			Relationships r=this.getRelationship(p.getId());
			p.setInterest(i);
			p.setRelationship(r);
		}
		RelatioshipRatingService.rankPariticipantByRelationship(this);
	}
	
	private void createInterests(){
		
		
	interestList.add(new Interests(1,"I don't regularly exercise", "knitting,diy,cooking", 0, 0, 0, "be the change you wish to see in the world", 0, "unique", "in uni-happy(i dont know what the future holds )", "lasagna", "soaps", "Mystery", "watch videos", "RnB", "Comedy", 0, "GCSE", "getting bad grades", "kindness", "not sharing", "baking", "being more confident"));
	interestList.add(new Interests(2, "2-4 days a week", "No hobbies", 0, 0, 0, "If a new day starts, dare to smile gratefully.", 0, "Loyal, supportive, outgoing.", "Finishing my PsyD", "Spaghetti Carbonnara", "Friends, Penny dreadful, Salem", "Mystery", "Relaxing, watching series, hunging out with friends", "RnB", "Comedy", 1, "Getting into the Grad School", "I dont know. Have a few in my personal life.", "Patience. ", "I am overreacting in some cases. ", "Helping others.", "Not learning from some of my experiences."));
	interestList.add(new Interests(3, "Once a week", "", 0, 0, 1, "", 0, "Outgoing, determined, and intuitive ", "", "Brownies", "", "Non-Fiction", "Sit and relax", "Pop", "Comedy", 1, "", "", "Positive attitude", "Stubbornness ", "Helping people follow their own passion", "Be more type B"));
	interestList.add(new Interests(4, "Once a week", "Video games, shopping, music", 0, 0, 0, "Oh it's so easy to say -   Give what you think you lack -  You feel unloved? Then give love, and love, and love......   On the other hand -  Do you have any better advice?", 0, "Small, hopeful, loving", "Eating nuggets", "Pasta", "The IT Crowd", "Action/Adventure", "Sleep", "Pop", "Comedy", 1, "Being a good friend", "Upsetting my mum", "Caring", "Over emotional ", "Making people laugh", "My laziness"));
	interestList.add(new Interests(5, "Once a week", "internet, music, cinema", 0, 0, 1, "work hard, play hard", 0, "smart, kind, handsome, stressful", "married with children and succesful at work", "meat, any", "friends", "Science", "going out, gym, internet", "Dance", "Sci-Fi", 0, "Being a good person in general", "The few times i let people down", "mind", "anxiety", "women and ... style", "less stress"));
	interestList.add(new Interests(6, "I don't regularly exercise", "Sleeping", 1, 1, 0, "Godson", 0, "Dumb", "An old man", "Rice", "", "Poetry", "Sleep", "Classical", "Action", 0, "", "", "", "", "", ""));
	interestList.add(new Interests(7, "Once a week", "Going for walks, origami, gymnastics", 0, 0, 0, "Magic, indeed, is all around us, in stones, flowers, stars, the dawn wind and the sunset cloud; all we need is the ability to see and understand.", 0, "Curious, dreamer, non-conformist", "In a tree", "Candy Floss", "Jesisca Jones, Arrow", "Action/Adventure", "Read, watch TV/Youtube, go for walks", "Pop", "Drama", 1, "Becoming a vegan", "", "", "Envy", "I love plants :D", "Clear my bad skin :/"));
	interestList.add(new Interests(8, "I don't regularly exercise", "", 0, 0, 1, "", 0, "", "", "", "Narcos, Dexter", "Non-Fiction", "", "Rock", "Mystery", 0, "", "", "", "", "", ""));
	interestList.add(new Interests(9, "I don't regularly exercise", "Reading, socialising, social media", 0, 0, 0, "N/A", 0, "Talkative, unique, nice", "Working probably", "Lamb", "My dream home, teen wolf", "Action/Adventure", "Watch TV, read books, socialise with friends, social media browse", "RnB", "Comedy", 1, "N/A", "N/A", "My personality", "My looks ", "God, music, literature etc", "N/A"));
	interestList.add(new Interests(10, "I don't regularly exercise", "reading, hanging out online, creative writing", 0, 0, 0, "Good-night, my- He stopped, bit his lip, and abruptly left me._??", 0, "annoying, sensitive, a thinker", "dead, or stuck in a job I dislike", "Xiao long bao (soup dumplings)", "Gilmore Girls, Brooklyn Nine Nine, ", "Drama", "Netflix!", "Pop", "Comedy", 0, "Staying alive this long", "Staying alive this long", "My supportive attitude", "My constant cycle of loving life and then hating i", "Literature", "Stop being so annoying"));
	interestList.add(new Interests(11, "", "Ukulele.  Skateboarding ", 0, 0, 5, "", 0, "Weirdo", "With a degree and working as some sort of physicist. Or on YouTube for some stupid reason ", "Pizza", "Got, Rick and Morty", "Action/Adventure", "My hobbies, masturbate ", "", "Comedy", 1, "Dunno tbh birth? ", "Having to go through clearing ", "I actually talk to people ", "I talk too much and don't make sense ", "Making friends ", "I'd be cooler"));
	interestList.add(new Interests(12, "2-4 days a week", "Drawing, reading, making jewllery", 0, 0, 0, "Dont judge anyone ever!!!!", 0, "Honest and lonely ....", "Probably be a grandmother", "protein, veggies, cheese and dessert", "Action series", "Drama", "Reading, listening to music, talking to people I love", "Pop", "Action", 1, "My children", "The lack of self confidence ", "Honesty", "when I feel negativity I cannot  suppress my feeli", "To help people to deal with their emotions", " I would have studied psychology and devote time to fine arts"));
	interestList.add(new Interests(13, "I don't regularly exercise", "", 0, 0, 0, "", 0, "", "", "", "", "Science", "", "Country", "Crime", 1, "", "", "", "", "", ""));
	interestList.add(new Interests(14, "I don't regularly exercise", "making puzzles", 0, 0, 0, "don't worry be happy", 0, "", "I hope to a better place", "spaghetti ", "walking dead,grey's anatomy, criminal minds and ma", "Mystery", "be on facebook", "Dance", "Crime", 1, "my son", "loosing my mother", "", "", "", ""));
	interestList.add(new Interests(15, "I don't regularly exercise", "reading", 0, 0, 1, "-", 0, "logical,persistent,shy", "traveling", "spaghetti", "Grimm,The 100 etc.", "Sci-Fi", "I don't have free time.", "Rock", "Romance", 0, "my degree", "my job", "faithfulness", "single-mindness", "Books", "More carefree"));

	}
	
	
	private void createRelationships(){
		relationshipsList.add(new Relationships(1,"Single", 0, 1, "0 months", "Heterosexual", "Married", "0 months", 0, 3, 1, 3, 3, 3, "family grades", "Hinduism"));
		relationshipsList.add(new Relationships(2, "Single", 16, 0, "3 years", "Heterosexual", "Married", "3 years", 0, 4, 3, 4, 4, 4, "Family honesty graditute", "Christianity (Catholic  Orthodox  etc)"));	
		relationshipsList.add(new Relationships(3, "Married", 17, 0, "19 years", "Heterosexual", "Married", "19 years", 4, 4, 3, 3, 4, 4, "Honesty and integrity ", "Christianity (Catholic  Orthodox  etc)"));
		relationshipsList.add(new Relationships(4, "Single", 13, 1, "3 months", "Bisexual", "Single", "0 months", 0, 3, 1, 4, 4, 4, "Honesty", "Agnostic"));
		relationshipsList.add(new Relationships(5, "In an open relationship", 17, 0, "7 years", "Heterosexual", "Married", "1 months", 0, 4, 5, 5, 3, 3, "kindness honesty helping people", "Christianity (Catholic  Orthodox  etc)"));
		relationshipsList.add(new Relationships(6, "Married", 37, 1, "11 years", "Bisexual", "Married", "11 years", 2, 1, 1, 1, 5, 5, "Sleeping", "Hinduism"));
		relationshipsList.add(new Relationships(7, "Single", 0, 1, "0 months", "Homosexual", "Married", "0 months", 0, 4, 1, 3, 5, 5, "Morality  freedom altruism", "Agnostic"));
		relationshipsList.add(new Relationships(8, "In an exclusive relationship", 13, 0, "4 years", "Heterosexual", "Married", "4 years", 0, 5, 1, 3, 2, 2, "n/a", "Christianity (Catholic  Orthodox  etc)"));
		relationshipsList.add(new Relationships(9, "Single", 0, 1, "0 months", "Heterosexual", "Married and single", "0 months", 0, 3, 1, 2, 3, 3, "friends God family", "Christianity (Catholic  Orthodox  etc)"));
		relationshipsList.add(new Relationships(10, "Single", 0, 1, "0 months", "Bisexual", "Divorced", "0 months", 0, 3, 1, 2, 3, 3, "honesty appreciation support", "Atheist"));
		relationshipsList.add(new Relationships(11, "Single", 16, 1, "2 months", "Heterosexual", "Single", "0 months", 0, 3, 1, 3, 3, 3, "Trust loyalty ", "Agnostic"));
		relationshipsList.add(new Relationships(12, "Married", 15, 0, "26 years ", "Heterosexual", "Married", "26 years", 2, 4, 2, 5, 4, 4, "To be honest and being around people I respect", "Christianity (Catholic  Orthodox  etc)"));
		relationshipsList.add(new Relationships(13, "In an exclusive relationship", 16, 0, "6 years", "Heterosexual", "Married", "6 years", 0, 2, 4, 2, 4, 4, "n/a", "Atheist"));
		relationshipsList.add(new Relationships(14, "Married", 15, 0, "20 years", "Heterosexual", "Widower", "20 years", 1, 4, 3, 2, 2, 2, "family", "Christianity (Catholic  Orthodox  etc)"));
		relationshipsList.add(new Relationships(15, "Single", 0, 1, "0 months", "Heterosexual", "Married", "0 months", 0, 4, 1, 2, 1, 1, "honesty respect politeness", "Other"));

	}
	
	public ArrayList<Participant> getParticipants(){
		return participantList;
	}
	
	public ArrayList<Relationships> getRelationships(){
		return  relationshipsList;
	}
	
	public Participant getParticipant(int id){
		for( Participant p : participantList){
			if (p.getId()==id){
				return p;
			}
		}
		return null;
	}
	
	public Relationships getRelationship(int id){
		for( Relationships r : relationshipsList){
			if (r.getId()==id){
				return r;
			}
		}
		return null;
	}
	
	public Interests getInterests(int id){
		for( Interests interest : interestList){
			if (interest.getId()==id){
				return interest;
			}
		}
		return null;
	}
	
	
	public Object[][] getParticipantsArray(){
		
		int size=participantList.size();
		Object[][] participantsArray=new Object[size][8];
		
		for(int i=0;i<size;i++){
			
			Participant p=participantList.get(i);
			participantsArray[i][0]=p.getId();
			participantsArray[i][1]=p.getAge();
			participantsArray[i][2]=p.getGender();
			participantsArray[i][3]=p.getEthnicity();
			participantsArray[i][4]=p.getOccupation();
			participantsArray[i][5]=p.getCountry();
			participantsArray[i][6]=p.getOrigin();
			participantsArray[i][7]=p.getEducation();
		}
		return participantsArray;
	}
	
	public String[] getParticipantsAttributes(){
		return new String[]{"ID","Age","Gender","Ethinicity","Occupation","Country","Origin","Education"};
	}
	
	public void TestReflection() throws NoSuchMethodException, ClassNotFoundException{
		Participant p;
		Object obj = null;
		Object obj1 = null;
		Class[] paramInt={Integer.TYPE};
		
		Class cls=Class.forName("project.Participant");
		try {
			 obj=cls.newInstance();
			Method method=cls.getDeclaredMethod("setId",paramInt);
			method.invoke(obj,27);
			
			 method=cls.getDeclaredMethod("getId",null);
			 obj1=method.invoke(obj,null);
			 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		int i=(Integer)obj1;
		System.out.println(obj1.getClass());
	//	p=(Participant)obj;
		System.out.println("Test");	
		
	}
	
	public void Test(){
		
		Object[] objects={String.class,"ID",23,new String[]{"1","2"}};
		
	}
	
	public int saveNewRecord(Object object){
		
		Class<?> formClass=object.getClass();
		int id=0;
		if (formClass==Participant.class){
			Participant p=(Participant)object;
			id=participantList.get(participantList.size()-1).getId()+1;
			p.setId(id);
			participantList.add(p);
		}
		else if (object.getClass()==Relationships.class){
			Relationships r=(Relationships)object;
			id=relationshipsList.get(relationshipsList.size()-1).getId()+1;
			r.setId(id);
			relationshipsList.add((Relationships)object);
		}
		else if (object.getClass()==Interests.class){
			Interests i=(Interests)object;
			id=interestList.get(interestList.size()-1).getId()+1;
			i.setId(id);
			interestList.add((Interests)object);
		}
		return id;
	}
	
	public void deleteRecords(Map<String,GenericForm3> forms){
		
		for(String formName : forms.keySet()){
			Object object=forms.get(formName).formConfigurator.getFormData();
			System.out.println(formName);
			if (object!=null){
				Class<?> className=object.getClass();
				System.out.println(className.getName());
				if (className==Participant.class){
					participantList.remove(object);
				}
				else if (className==Interests.class){
					interestList.remove(object);
				}
				else relationshipsList.remove(object);
			}
			
		}
	}

}
