class AttachChildEnvironmentRequestValidator implements Validator<AttachChildEnvironmentRequest> {

    @Override
    public ValidationResult validate(AttachChildEnvironmentRequest subject) {
        ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();

        String accountId = crnService.getCurrentAccountId();
        if (stackService.findAllByEnvironmentCrnAndAccountId(subject.getParentEnvironmentCrn(), accountId).isEmpty()) {
            validationBuilder.error(PARENT_ENVIRONMENT_SHOULD_HAVE_A_STACK);
        }
        if (!stackService.findAllByEnvironmentCrnAndAccountId(subject.getChildEnvironmentCrn(), accountId).isEmpty()) {
            validationBuilder.error(CHILD_ENVIRONMENT_ALREADY_HAS_A_STACK);
        }
        if (childEnvironmentService.isChildEnvironment(subject.getParentEnvironmentCrn(), accountId)) {
            validationBuilder.error(PARENT_ENVIRONMENT_CAN_NOT_BE_A_CHILD_ENVIRONMENT);
        }
        if (childEnvironmentService.isChildEnvironment(subject.getChildEnvironmentCrn(), accountId)) {
            validationBuilder.error(CHILD_ENVIRONMENT_ALREADY_HAS_A_PARENT_ENVIRONMENT);
        }

        return validationBuilder.build();
    }

}