package org.amc.game.chessserver.messaging;

import java.io.File;

import org.amc.game.chess.Player;
import org.amc.game.chessserver.AbstractServerChessGame;

public class PlayerQuitChessGameEmail extends EmailTemplate {

	static final String EMAIL_TEMPLATE = "quitGameEmail.html";
	
	private static final int GAMEUID_LENGTH = 5;
	
	static final String DEFAULT_EMAIL_SUBJECT = "Game update from AMCChessGame";
	
	static final String NO_VALID_UID_MESSAGE = "No Game Uid";
	
	public PlayerQuitChessGameEmail() {
		super();
		setEmailTemplateName(EMAIL_TEMPLATE);
		setEmailSubject(DEFAULT_EMAIL_SUBJECT);
		
	}
	
	public PlayerQuitChessGameEmail(Player player, AbstractServerChessGame serverChessGame){
		this();
	    setPlayer(player);
	    setServerChessGame(serverChessGame);
	    
    }

	@Override
    public void addContextVariables() {
	    addContextVariable("name", getServerChessGame().getPlayer().getName());
	    addContextVariable("player", getPlayer().getName());
	    String gameUid = String.valueOf(getServerChessGame().getUid());
        String gameUidFragment = gameUid.length() > GAMEUID_LENGTH ? gameUid.substring(gameUid.length() - GAMEUID_LENGTH, gameUid.length()) : NO_VALID_UID_MESSAGE;
        addContextVariable("GAME_UUID", gameUidFragment);
        addContextVariable(TEMPLATE_BACKGROUND_TAG, BACKGROUND_IMAGE_RESOURCE);
	}

    @Override
    public void addImages() {
        addEmbeddedImage(BACKGROUND_IMAGE_RESOURCE, new File(backgroundImagePath));
    }
	
}

@@ -275,17 +275,16 @@
 .html%22;%0A
-%09
 %0A%09privat
@@ -322,17 +322,16 @@
 TH = 5;%0A
-%09
 %0A%09static
@@ -401,17 +401,16 @@
 sGame%22;%0A
-%09
 %0A%09static
@@ -461,17 +461,16 @@
 e Uid%22;%0A
-%09
 %0A%09public
@@ -596,15 +596,12 @@
 T);%0A
-%09%09
 %0A%09%7D%0A
-%09
 %0A%09pu
@@ -685,16 +685,17 @@
 essGame)
+ 
 %7B%0A%09%09this
@@ -699,20 +699,17 @@
 his();%0A%09
-    
+%09
 setPlaye
@@ -720,20 +720,17 @@
 ayer);%0A%09
-    
+%09
 setServe
@@ -762,18 +762,10 @@
 e);%0A
+%0A
 %09
-    %0A    
 %7D%0A%0A%09
@@ -766,36 +766,33 @@
 %0A%09%7D%0A%0A%09@Override%0A
-    
+%09
 public void addC
@@ -812,20 +812,17 @@
 es() %7B%0A%09
-    
+%09
 addConte
@@ -886,20 +886,17 @@
 me());%0A%09
-    
+%09
 addConte
@@ -941,20 +941,17 @@
 me());%0A%09
-    
+%09
 String g
@@ -1006,24 +1006,18 @@
 Uid());%0A
-        
+%09%09
 String g
@@ -1066,17 +1066,21 @@
 D_LENGTH
- 
+%0A%09%09%09%09
 ? gameUi
@@ -1168,24 +1168,18 @@
 ESSAGE;%0A
-        
+%09%09
 addConte
@@ -1220,24 +1220,18 @@
 gment);%0A
-        
+%09%09
 addConte
@@ -1298,20 +1298,17 @@
 E);%0A%09%7D%0A%0A
-    
+%09
 @Overrid
@@ -1309,20 +1309,17 @@
 verride%0A
-    
+%09
 public v
@@ -1340,16 +1340,10 @@
 ) %7B%0A
-        
+%09%09
 addE
@@ -1418,14 +1418,10 @@
 ));%0A
-    
+%09
 %7D%0A
-%09
 %0A%7D%0A

fix format