package core.user;

import core.process.Condition;
import core.process.ProcessManagement;
import core.user.userFun.AccountManageable;
import core.user.userFun.ProcessConfigurable;
import core.user.utils.AccountManagement;

import java.util.List;
import java.util.Map;

public abstract class User implements AccountManageable, ProcessConfigurable{

    private String id;
    private String password;
    private String name;
    private String e_mail_location;
    private String phone_number;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getE_mail_location() {
        return e_mail_location;
    }

    public void setE_mail_location(String e_mail_location) {
        this.e_mail_location = e_mail_location;
    }

    public String getPhone_number() {
        return phone_number;
    }

    public void setPhone_number(String phone_number) {
        this.phone_number = phone_number;
    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }

    private String phonenumber;
    private List<String> permissions = null;
    public Condition getCondition() {
        return condition;
    }

    public void setCondition(Condition condition) {
        this.condition = condition;
    }

    private Condition condition;
    public void addPermission(String permission){
        if(!permissions.contains(permission))
            permissions.add(permission);
    }
    public void removePermission(String permission){
        permissions.remove(permission);
    }
    public boolean checkPermission(String permission){
        return permissions.contains(permission);

    }
    public User(){
        super();

    }
    public abstract String getType();

    public void destroy(){
        core.user.utils.AccountManagement.destroy(this);
    }

    public void logout(){
        core.user.utils.AccountManagement.logout(this);
    }

    @Override
    public void syncToDatabase() {

    }

    @Override
    public void syncFromDatabase() {

    }

    public void setAttr(Map<String, String> vMap){
        this.setId(vMap.get("id"));
        this.setName(vMap.get("name"));
        this.setE_mail_location(vMap.get("e_mail_location"));
        this.setPhone_number(vMap.get("phone_number"));
    }


    public void initCondition() throws Exception {
        this.condition = ProcessManagement.getCondition(this);
    }
}
