package nl.novi.eindopdracht.LoginAndSecurity.Model;


import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import nl.novi.eindopdracht.Image.ImageData;

import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name="users")
public class User {

    @Column
    @NotBlank
    private String name;

    // Deze eerste 3 variabelen zijn verplicht om te kunnen inloggen met een username, password en rol.
    //HIER NOG EEN NAAM TOEVOEGEN
    @Id

    @Column(nullable = false, unique = true)
    @NotBlank
    private String username;

    @Column(nullable = false, length = 255)
    @NotBlank
    private String password;

    @Column
    @NotBlank
    private String email;

    @OneToMany(
            targetEntity = Authority.class,
            mappedBy = "username",
            cascade = CascadeType.ALL,
            orphanRemoval = true,
            fetch = FetchType.EAGER)
    private Set<Authority> authorities = new HashSet<>();


    // Deze 3 variabelen zijn niet verplicht.
    // Je mag ook een "String banaan;" toevoegen, als je dat graag wilt.
    @Column(nullable = false)
    private boolean enabled = true;

    @Column
    private String apikey;

    @OneToOne(mappedBy = "user", fetch = FetchType.LAZY)
    private ImageData imageData;

    public String getName() {
        return name;
    }

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

    public String getUsername() { return username; }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public boolean isEnabled() { return enabled;}
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    public String getApikey() { return apikey; }
    public void setApikey(String apikey) { this.apikey = apikey; }
    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email;}

    public Set<Authority> getAuthorities() { return authorities; }
    public void addAuthority(Authority authority) {
        this.authorities.add(authority);
    }
    public void removeAuthority(Authority authority) {
        this.authorities.remove(authority);
    }

    public  ImageData getImageData() {
        return imageData;
    }

    public void setImage(ImageData imageData) {
        this.imageData = imageData;
    }

    public void setImageData(Object o) {
    }
}

// Deze eerste 3 variabelen zijn verplicht om te kunnen inloggen met een username, password en rol.
package nl.novi.eindopdracht.LoginAndSecurity.Model;


import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import nl.novi.eindopdracht.Image.ImageData;

import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name="users")
public class User {

    @Column
    @NotBlank
    private String name;

    // Deze eerste<SUF>
    //HIER NOG EEN NAAM TOEVOEGEN
    @Id

    @Column(nullable = false, unique = true)
    @NotBlank
    private String username;

    @Column(nullable = false, length = 255)
    @NotBlank
    private String password;

    @Column
    @NotBlank
    private String email;

    @OneToMany(
            targetEntity = Authority.class,
            mappedBy = "username",
            cascade = CascadeType.ALL,
            orphanRemoval = true,
            fetch = FetchType.EAGER)
    private Set<Authority> authorities = new HashSet<>();


    // Deze 3 variabelen zijn niet verplicht.
    // Je mag ook een "String banaan;" toevoegen, als je dat graag wilt.
    @Column(nullable = false)
    private boolean enabled = true;

    @Column
    private String apikey;

    @OneToOne(mappedBy = "user", fetch = FetchType.LAZY)
    private ImageData imageData;

    public String getName() {
        return name;
    }

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

    public String getUsername() { return username; }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public boolean isEnabled() { return enabled;}
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    public String getApikey() { return apikey; }
    public void setApikey(String apikey) { this.apikey = apikey; }
    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email;}

    public Set<Authority> getAuthorities() { return authorities; }
    public void addAuthority(Authority authority) {
        this.authorities.add(authority);
    }
    public void removeAuthority(Authority authority) {
        this.authorities.remove(authority);
    }

    public  ImageData getImageData() {
        return imageData;
    }

    public void setImage(ImageData imageData) {
        this.imageData = imageData;
    }

    public void setImageData(Object o) {
    }
}
