package org.cobbzilla.wizard.auth;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import static org.cobbzilla.util.daemon.ZillaRuntime.empty;

@NoArgsConstructor @Accessors(chain=true)
public class LoginRequest {

    public LoginRequest (String name, String password) {
        this.name = name;
        this.password = password;
    }

    public boolean forceLowercase () { return true; }

    @Setter private String name;
    public String getName () { return name == null ? null : (forceLowercase() ? name.toLowerCase() : name).trim(); }
    public boolean hasName () { return !empty(name); }

    public String getUsername () { return getName(); }
    public LoginRequest setUsername (String name) { return name == null ? null : setName(name); }

    @Getter @Setter @JsonProperty private String password;
    public boolean hasPassword () { return !empty(password); }

    @Getter @Setter @JsonProperty private String totpToken;
    @JsonIgnore public boolean hasTotpToken() { return !empty(totpToken); }

    @Getter @Setter private String deviceId;
    @JsonIgnore public boolean hasDevice () { return !empty(deviceId); }

    @Getter @Setter private String deviceName;

    // optional - server-side resource can fill this in for other server-side code to use
    @JsonIgnore @Getter @Setter private String userAgent;

    public String toString () {
        return "{name="+getName()+", password="+mask(password)+", totpToken="+mask(totpToken)+", device="+getDevice()+"}";
    }

    @JsonIgnore public String getDevice() { return hasDevice() ? deviceId + " ("+deviceName+")" : "NOT-SET"; }

    public String mask(String value) { return empty(value) ? "NOT-SET" : "SET"; }
}

@@ -1223,18 +1223,16 @@
 g device
-Id
 ;%0A    @J
@@ -1295,64 +1295,14 @@
 vice
-Id
 ); %7D%0A%0A
-    @Getter @Setter private String deviceName;%0A%0A
     
@@ -1612,120 +1612,8 @@
  %7D%0A%0A
-    @JsonIgnore public String getDevice() %7B return hasDevice() ? deviceId + %22 (%22+deviceName+%22)%22 : %22NOT-SET%22; %7D%0A%0A
     

replace deviceId/deviceName with just device