package com.ecep.contract.util;

import com.ecep.contract.service.SysConfService;

import javafx.beans.property.SimpleBooleanProperty;

public class BooleanConfigProperty extends SimpleBooleanProperty {

    private final String key;
    private final SysConfService service;

    public BooleanConfigProperty(String key, SysConfService service) {
        this(key, service, service.getBoolean(key));
    }

    public BooleanConfigProperty(String key, SysConfService service, boolean initialValue) {
        super(initialValue);
        System.out.println("key = " + key + ", initialValue = " + initialValue);
        this.key = key;
        this.service = service;
    }

    @Override
    protected void invalidated() {
        super.invalidated();
        System.out.println("key = " + key + ", set = " + get());
        service.set(key, Boolean.toString(get()));
    }
}
