package com.backendsys.entity.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.web.multipart.MultipartFile;

public class MultipartFileSizeValidator implements ConstraintValidator<FileSizeLimit, MultipartFile> {
    private long maxSize;

    @Override
    public void initialize(FileSizeLimit fileSizeLimit) {
        this.maxSize = fileSizeLimit.maxSize();
    }

    @Override
    public boolean isValid(MultipartFile file, ConstraintValidatorContext context) {
        return (file != null && file.getSize() <= maxSize);
    }
}
