package com.imprimelibros.erp.users.validation;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

/**
 * DTO del formulario de creación/edición de usuarios
 * (No ensucia la entidad y permite validaciones específicas de UI)
 */
@PasswordsMatch(password = "password", confirmPassword = "confirmPassword", groups = UserForm.Create.class)
public class UserForm {

    /** Grupos de validación */
    public interface Create {
    }

    public interface Update {
    }

    private Long id;

    @NotBlank(message = "{usuarios.error.nombre}", groups = { Create.class, Update.class })
    private String fullName;

    @NotBlank(message = "{usuarios.error.email}", groups = { Create.class, Update.class })
    @Email(message = "{usuarios.error.email.formato}", groups = { Create.class, Update.class })
    private String userName;

    @NotBlank(message = "{usuarios.error.rol}", groups = { Create.class, Update.class })
    @Pattern(regexp = "USER|ADMIN|SUPERADMIN", message = "{usuarios.error.rol.invalido}", groups = { Create.class,
            Update.class })
    private String roleName;

    // Obligatoria solo al crear
    @NotBlank(message = "{usuarios.error.password.requerida}", groups = Create.class)
    @Size(min = 6, message = "{usuarios.error.password.min}", groups = Create.class)
    private String password;

    // Validada por @PasswordsMatch (y requerida al crear)
    @NotBlank(message = "{usuarios.error.confirmPassword.requerida}", groups = Create.class)
    private String confirmPassword;

    @NotNull(groups = { Create.class, Update.class })
    private Boolean enabled;

    // ===== Getters / Setters =====
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }
}
