package org.example.petshopdesktop.auth;

public class UserSession {
    private static UserSession instance;

    private Long userId;
    private Long employeeId;
    private String username;
    private String employeeName;
    private Role role;
    private String jwtToken;
    private Long storeId;
    private String avatarUrl;

    private UserSession() {}

    public static UserSession getInstance() {
        if (instance == null) {
            instance = new UserSession();
        }
        return instance;
    }

    public void login(Long userId, String username, Role role, String jwtToken) {
        this.userId = userId;
        this.employeeId = userId;
        this.username = username;
        this.employeeName = username;
        this.role = role;
        this.jwtToken = jwtToken;
    }

    public void logout() {
        this.userId = null;
        this.employeeId = null;
        this.username = null;
        this.employeeName = null;
        this.role = null;
        this.jwtToken = null;
        this.storeId = null;
        this.avatarUrl = null;
    }

    public Long getUserId() {
        return userId;
    }

    public Long getEmployeeId() {
        return employeeId;
    }

    public String getUsername() {
        return username;
    }

    public String getEmployeeName() {
        return employeeName;
    }

    public Role getRole() {
        return role;
    }

    public String getJwtToken() {
        return jwtToken;
    }

    public Long getStoreId() {
        return storeId;
    }

    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }

    public boolean isLoggedIn() {
        return username != null && role != null;
    }

    public boolean isAdmin() {
        return Role.ADMIN.equals(role);
    }

    public boolean isStaff() {
        return Role.STAFF.equals(role);
    }
}
