package cl.monsoon.s1next.model;

import android.text.TextUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import cl.monsoon.s1next.Config;

@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account {

    @JsonProperty("member_username")
    private String username;

    @JsonProperty("member_uid")
    private String uid;

    @JsonProperty("formhash")
    private String authenticityToken;

    public String getUsername() {
        return username;
    }

    /**
     * Store user info when has logged in (just now or before).
     */
    public void setUsername(String username) {
        this.username = username;

        if (Config.getUsername() == null && !TextUtils.isEmpty(username)) {
            Config.setUsername(username);
        } else if (Config.getUsername() != null && TextUtils.isEmpty(username)) {
            Config.setUsername(null);
        }
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;

        // uid.equals("0") = true when user hasn't logged in
        if (Config.getUid() == null && !TextUtils.isEmpty(uid) && !uid.equals("0")) {
            Config.setUid(uid);
        } else if (Config.getUid() != null && (TextUtils.isEmpty(uid) || uid.equals("0"))) {
            Config.setUid(null);
        }
    }

    public String getAuthenticityToken() {
        return authenticityToken;
    }

    public void setAuthenticityToken(String authenticityToken) {
        this.authenticityToken = authenticityToken;

        if (Config.getAuthenticityToken() == null && !TextUtils.isEmpty(authenticityToken)) {
            Config.setAuthenticityToken(authenticityToken);
        } else if (Config.getAuthenticityToken() != null &&
                !authenticityToken.equals(Config.getAuthenticityToken())) {
            Config.setAuthenticityToken(null);
        }
    }
}

@@ -754,41 +754,8 @@
 if (
-Config.getUsername() == null && !
 Text
@@ -812,24 +812,20 @@
 sername(
-username
+null
 );%0A     
@@ -837,73 +837,8 @@
 else
- if (Config.getUsername() != null && TextUtils.isEmpty(username))
  %7B%0A 
@@ -859,36 +859,40 @@
 fig.setUsername(
-null
+username
 );%0A        %7D%0A   
@@ -1090,36 +1090,8 @@
 if (
-Config.getUid() == null && !
 Text
@@ -1109,20 +1109,19 @@
 ty(uid) 
-&& !
+%7C%7C 
 uid.equa
@@ -1157,19 +1157,20 @@
 .setUid(
-uid
+null
 );%0A     
@@ -1182,84 +1182,8 @@
 else
- if (Config.getUid() != null && (TextUtils.isEmpty(uid) %7C%7C uid.equals(%220%22)))
  %7B%0A 
@@ -1199,36 +1199,35 @@
   Config.setUid(
-null
+uid
 );%0A        %7D%0A   
@@ -1448,50 +1448,8 @@
 if (
-Config.getAuthenticityToken() == null && !
 Text
@@ -1524,33 +1524,20 @@
 tyToken(
-authenticityToken
+null
 );%0A     
@@ -1550,103 +1550,30 @@
 lse 
-if (Config.getAuthenticityToken() != null &&%0A                !authenticityToken.equals(
+%7B%0A            
 Config.
-g
+s
 etAu
@@ -1592,37 +1592,9 @@
 ken(
-))) %7B%0A            Config.setA
+a
 uthe
@@ -1597,37 +1597,32 @@
 uthenticityToken
-(null
 );%0A        %7D%0A   

Fix the wrong setter in `Account` model