package com.ecep.contract.vm;

import com.ecep.contract.model.SysConf;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;

import java.time.LocalDateTime;
import java.util.Objects;

public class SysConfViewModel extends BaseViewModel<SysConf> {
    private SimpleStringProperty id = new SimpleStringProperty();
    private SimpleStringProperty value = new SimpleStringProperty();
    private SimpleObjectProperty<LocalDateTime> modified = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> created = new SimpleObjectProperty<>();

    @Override
    protected void updateFrom(SysConf v) {
        super.updateFrom(v);
        id.set(v.getId());
        value.set(v.getValue());
        modified.set(v.getModified());
        created.set(v.getCreated());
    }

    @Override
    public boolean copyTo(SysConf v) {
        boolean ret = super.copyTo(v);
        if (!Objects.equals(id.get(), v.getId())) {
            v.setId(id.get());
            ret = true;
        }
        if (!Objects.equals(value.get(), v.getValue())) {
            v.setValue(value.get());
            ret = true;
        }
        if (!Objects.equals(modified.get(), v.getModified())) {
            v.setModified(modified.get());
            ret = true;
        }
        if (!Objects.equals(created.get(), v.getCreated())) {
            v.setCreated(created.get());
            ret = true;
        }
        return ret;
    }
}
