package kr.iotdoor.boot.model.user;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

public class AdminUserPrincipal implements UserDetails {

    private final UserAccount userAccount;

    public AdminUserPrincipal(UserAccount userAccount) {
        this.userAccount = userAccount;
    }

    public String getUserIdntfNo() {
        return userAccount.getUserIdntfNo();
    }

    public String getDisplayName() {
        return userAccount.getUserNm();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of(new SimpleGrantedAuthority("ROLE_ADMIN"));
    }

    @Override
    public String getPassword() {
        return userAccount.getPswd();
    }

    @Override
    public String getUsername() {
        return userAccount.getUserId();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !"Y".equalsIgnoreCase(userAccount.getLockYn());
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return "A".equalsIgnoreCase(userAccount.getUserSttsCd()) || "P".equalsIgnoreCase(userAccount.getUserSttsCd());
    }
}
