/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.files;

import java.util.Arrays;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import model.person.Person;

/**
 *
 * @author patri
 */
@Entity
public class UserPicture extends FileDB{
    private static List<Mime> allowedFileTypes = Arrays.asList(Mime.JPEG, Mime.JPG, Mime.PNG, Mime.BMP, Mime.PNG);
    private static long sizeLimit = 2000000L;
    
    @OneToOne(optional = false, cascade = {CascadeType.MERGE, CascadeType.REFRESH})
    private Person person;

    public UserPicture() {
    }
    
    public static String getAllowedTypesRE(){
        StringBuilder output = new StringBuilder(allowedFileTypes.size() * 4);
        
        output.append("/(\\.|\\/)(");
        
        for(int i = 0; i < allowedFileTypes.size(); i++){
            output.append(allowedFileTypes.get(i).getExtension());
            if (i < allowedFileTypes.size() -1) {
                output.append('|');
            }
        }
        
        output.append(")$/");
        
        return output.toString();
    }

    public static List<Mime> getAllowedFileTypes() {
        return allowedFileTypes;
    }

    public static void setAllowedFileTypes(List<Mime> allowedFileTypes) {
        UserPicture.allowedFileTypes = allowedFileTypes;
    }

    public static long getSizeLimit() {
        return sizeLimit;
    }

    public static void setSizeLimit(long sizeLimit) {
        UserPicture.sizeLimit = sizeLimit;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }
}
