package com.oguerreiro.resilient.security.custom;

import java.util.Collection;

import org.springframework.security.core.AuthenticatedPrincipal;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import com.oguerreiro.resilient.domain.Organization;
import com.oguerreiro.resilient.security.resillient.SecurityGroup;

public class ResilientUserDetails extends User implements AuthenticatedPrincipal {

  private final SecurityGroup securityGroup; // The security group permissions for the user
  private final Organization parentOrganization;  // The parent organization where the user is within the organogram
  private final String langKey; //User language

  public ResilientUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities,
      SecurityGroup securityGroup, Organization parentOrganization, String langKey) {
    super(username, password, true, true, true, true, authorities);
    this.securityGroup = securityGroup;
    this.parentOrganization = parentOrganization;
    this.langKey = langKey;
  }

  public SecurityGroup getSecurityGroup() {
    return securityGroup;
  }

  public String getLangKey() {
    return langKey;
  }

  public Organization getParentOrganization() {
    return parentOrganization;
  }

  @Override
  public String getName() {
    return super.getUsername();
  }

}
