package com.ecep.contract.vm;

import com.ecep.contract.UnitType;
import com.ecep.contract.vo.UnitVo;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class UnitViewModel extends IdentityViewModel<UnitVo> {
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleObjectProperty<UnitType> unitType = new SimpleObjectProperty<>();
    private SimpleDoubleProperty ratio = new SimpleDoubleProperty();
    private SimpleBooleanProperty standard = new SimpleBooleanProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleBooleanProperty active = new SimpleBooleanProperty();

    public static UnitViewModel from(UnitVo v) {
        UnitViewModel vm = new UnitViewModel();
        vm.update(v);
        return vm;
    }

    @Override
    protected void updateFrom(UnitVo v) {
        super.updateFrom(v);
        getCode().set(v.getCode());
        getName().set(v.getName());
        getUnitType().set(v.getUnitType());
        getRatio().set(v.getRatio());
        getStandard().set(v.isStandard());
        getDescription().set(v.getDescription());
        getActive().set(v.isActive());
    }
}