package Database;

import lombok.Getter;
import lombok.Setter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static Config.SomeCodes.ValidString;

@Getter
public class TinyLogRow {
    private @Setter int index;
    private final String DateTime;
    private final String Category;
    private final String Message;

    public TinyLogRow(int index, String datetime, String category, String message){
        this.index = index;
        this.DateTime = datetime;
        this.Category = category;
        this.Message = message;
    }

    public boolean HaveContent(){
        return ValidString(DateTime) & ValidString(Category) & ValidString(Message);
    }

    public static TinyLogRow Regex(String input){
        final String regex = "^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\s([A-Z]+:)\\s(.*)$";
        final Pattern pattern = Pattern.compile(regex);
        final Matcher matcher = pattern.matcher(input);
        if (matcher.find()){
            return new TinyLogRow(0, matcher.group(1), matcher.group(2), matcher.group(3));
        }
        return null;
    }
}
