package dev.lions.unionflow.client.dto.auth;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

public class LoginResponse {
    
    private String accessToken;
    private String refreshToken;
    private String tokenType = "Bearer";
    private Long expiresIn;
    private LocalDateTime expirationDate;
    
    private UserInfo user;
    
    public LoginResponse() {}
    
    public LoginResponse(String accessToken, String refreshToken, Long expiresIn, UserInfo user) {
        this.accessToken = accessToken;
        this.refreshToken = refreshToken;
        this.expiresIn = expiresIn;
        this.user = user;
        this.expirationDate = LocalDateTime.now().plusSeconds(expiresIn);
    }
    
    public String getAccessToken() {
        return accessToken;
    }
    
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
    
    public String getRefreshToken() {
        return refreshToken;
    }
    
    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }
    
    public String getTokenType() {
        return tokenType;
    }
    
    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }
    
    public Long getExpiresIn() {
        return expiresIn;
    }
    
    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
        if (expiresIn != null) {
            this.expirationDate = LocalDateTime.now().plusSeconds(expiresIn);
        }
    }
    
    public LocalDateTime getExpirationDate() {
        return expirationDate;
    }
    
    public void setExpirationDate(LocalDateTime expirationDate) {
        this.expirationDate = expirationDate;
    }
    
    public UserInfo getUser() {
        return user;
    }
    
    public void setUser(UserInfo user) {
        this.user = user;
    }
    
    public boolean isExpired() {
        return expirationDate != null && LocalDateTime.now().isAfter(expirationDate);
    }
    
    public static class UserInfo {
        private UUID id;
        private String nom;
        private String prenom;
        private String email;
        private String username;
        private String typeCompte;
        private List<String> roles;
        private List<String> permissions;
        private EntiteInfo entite;
        
        public UserInfo() {}
        
        public UUID getId() {
            return id;
        }
        
        public void setId(UUID id) {
            this.id = id;
        }
        
        public String getNom() {
            return nom;
        }
        
        public void setNom(String nom) {
            this.nom = nom;
        }
        
        public String getPrenom() {
            return prenom;
        }
        
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
        
        public String getEmail() {
            return email;
        }
        
        public void setEmail(String email) {
            this.email = email;
        }
        
        public String getUsername() {
            return username;
        }
        
        public void setUsername(String username) {
            this.username = username;
        }
        
        public String getTypeCompte() {
            return typeCompte;
        }
        
        public void setTypeCompte(String typeCompte) {
            this.typeCompte = typeCompte;
        }
        
        public List<String> getRoles() {
            return roles;
        }
        
        public void setRoles(List<String> roles) {
            this.roles = roles;
        }
        
        public List<String> getPermissions() {
            return permissions;
        }
        
        public void setPermissions(List<String> permissions) {
            this.permissions = permissions;
        }
        
        public EntiteInfo getEntite() {
            return entite;
        }
        
        public void setEntite(EntiteInfo entite) {
            this.entite = entite;
        }
        
        public String getNomComplet() {
            if (prenom != null && nom != null) {
                return prenom + " " + nom;
            }
            return nom != null ? nom : username;
        }
    }
    
    public static class EntiteInfo {
        private UUID id;
        private String nom;
        private String type;
        private String pays;
        private String ville;
        
        public EntiteInfo() {}
        
        public UUID getId() {
            return id;
        }
        
        public void setId(UUID id) {
            this.id = id;
        }
        
        public String getNom() {
            return nom;
        }
        
        public void setNom(String nom) {
            this.nom = nom;
        }
        
        public String getType() {
            return type;
        }
        
        public void setType(String type) {
            this.type = type;
        }
        
        public String getPays() {
            return pays;
        }
        
        public void setPays(String pays) {
            this.pays = pays;
        }
        
        public String getVille() {
            return ville;
        }
        
        public void setVille(String ville) {
            this.ville = ville;
        }
    }
}