package kz.cafe.db.model;

import java.util.*;
import kz.cafe.constants.*;
import kz.cafe.db.model.anotations.*;
import com.google.code.morphia.annotations.*;



@Entity(value="UserProfile", noClassnameStored=true, concern = "SAFE")
public class MUser extends MAbstractEditableDataElement{
   private static final long serialVersionUID = -1043450645053950858L;
   
   
   @AnnotationNotExported
   public static final String F_UID         = "ID";
   @AnnotationNotExported
   public static final String F_LOGIN       = "login";
   @AnnotationNotExported
   public static final String F_PASSWORD    = "password";

   
   
   public static final String F_CAN_USE_GUI = "canUseGUI";
   
   
   @AnnotationNotExported
   public static final String F_COUNTER_ORDERS_TOTAL = "cntrOrdersTotal"; 
   @AnnotationNotExported
   public static final String F_COUNTER_ORDERS_PAID  = "cntrOrdersPaid";
   
   
   @AnnotationNotExported
   public static final String F_EMAIL_CONFIRMED      = "emailConfirmed";
   
   
   


   @Indexed(unique = true)
   public String login = "user_" + System.currentTimeMillis() / 1000;
   public String password = "";
   
   public boolean emailConfirmed = false;

   
   @AnnotationRelated(foreign = MRole.class)
   public Integer role;
   
   
   public boolean active = true;
   public boolean canUseGUI = false;
   
   public InterfaceConstants.LANGS lang;   
   
   public String name = "";
   public String phone = "";
   
   @AnnotationRelated(foreign = MCity.class)
   public Integer city;
   
   public boolean gender;
   
   public long birthdate;
   
   
   public Device device;
   public List<Device> devices = new ArrayList<Device>();
   
   
   public long dateRegistration = System.currentTimeMillis();
   public long dateLatestLogin;
   
   
   @AnnotationImage
   public String image = InterfaceConstants.EMPTY_IMAGE;

   
   
   public int cntrOrdersTotal;
   public int cntrOrdersPaid;
   
   
   public boolean hasEmailNotifications = false;
   
   
   public static class Device{
      public String name;
      public String os;



      public Device(){
      }
      



      public Device(String name, String os){
         this.name = name;
         this.os = os;
      }





      @Override
      public int hashCode(){
         final int prime = 31;
         int result = 1;
         result = prime * result + ((name == null) ? 0 : name.hashCode());
         result = prime * result + ((os == null) ? 0 : os.hashCode());
         return result;
      }





      @Override
      public boolean equals(Object obj){
         if(this == obj)
            return true;
         if(obj == null)
            return false;
         if(getClass() != obj.getClass())
            return false;
         Device other = (Device) obj;
         if(name == null){
            if(other.name != null)
               return false;
         }
         else if(!name.equals(other.name))
            return false;
         if(os == null){
            if(other.os != null)
               return false;
         }
         else if(!os.equals(other.os))
            return false;
         return true;
      }




      @Override
      public String toString(){
         return "OS=" + os + ", ID=" + name;
      }
   }
   
   
   
   
   
   @Override   
   public String humanReadable(InterfaceConstants.LANGS lang){
      //return login + " [" + ID + "]";
      return login;
   }
}


