package domain.dto.request;

import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@RegisterForReflection
public class CustomerRequest {

    @Valid
    @NotNull(message = "VDE01")
    private CustomerPositionState customerPositionState;

    @Valid
    @NotNull(message = "VDE01")
    private Device device;

//    @Valid
//    @NotNull(message = "VDE01")
    private TokenAssignmentInstance tokenAssignmentInstance;
    private String productReferenceSearch;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class CustomerPositionState {

        @Valid
        @NotNull(message = "VDE01")
        private CustomerReference customerReference;

        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        @RegisterForReflection
        public static class CustomerReference {

            /**
             * Valida que sea una única letra del conjunto [V, E, P, G, J].
             */
            @NotBlank(message = "VDE01")
            @Pattern(regexp = "^[VEPGJ]$", message = "VDE02")
            private String customerIdType;

            /**
             * Valida que sea numérico con un máximo de 9 dígitos.
             */
            @NotBlank(message = "VDE01")
            @Pattern(regexp = "^$|^[0-9]{4,9}$", message = "VDE02")
            private String customerId;

        }

    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @RegisterForReflection
    public static class Device {
        @NotBlank(message = "VDE01")
        private String deviceType;

        @NotBlank(message = "VDE01")
        private String deviceDescription;

        @NotBlank(message = "VDE01")
        private String deviceIp;

        @NotBlank(message = "VDE01")
        private String deviceSessionReference;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @RegisterForReflection
    public static class TokenAssignmentInstance {

        /**
         * Este campo puede ser nulo, vacío ("") o un string de 8 dígitos.
         */
        @Pattern(regexp = "^$|^[0-9]{8}$", message = "VDE02")
        private String tokenIdentificationCode;

    }

}