package com.ecep.contract.vm;

import java.time.LocalDate;
import java.util.Objects;

import com.ecep.contract.vo.DeliverySignMethodVo;

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

/**
 * 交付或签收方式
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class DeliverySignMethodViewModel extends IdentityViewModel<DeliverySignMethodVo> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    
    private SimpleObjectProperty<LocalDate> created = new SimpleObjectProperty<>();

    private SimpleObjectProperty<Integer> saleType = new SimpleObjectProperty<>();

    public static DeliverySignMethodViewModel from(DeliverySignMethodVo v) {
        DeliverySignMethodViewModel model = new DeliverySignMethodViewModel();
        model.update(v);
        return model;
    }

    @Override
    protected void updateFrom(DeliverySignMethodVo v) {
        super.updateFrom(v);
        getName().set(v.getName());
        getCode().set(v.getCode());
        getDescription().set(v.getDescription());
        getSaleType().set(v.getSaleTypeId());
    }

    @Override
    public boolean copyTo(DeliverySignMethodVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getName().get(), v.getName())) {
            v.setName(getName().get());
            modified = true;
        }
        if (!Objects.equals(getCode().get(), v.getCode())) {
            v.setCode(getCode().get());
            modified = true;
        }
        if (!Objects.equals(getDescription().get(), v.getDescription())) {
            v.setDescription(getDescription().get());
            modified = true;
        }
        if (!Objects.equals(getSaleType().get(), v.getSaleTypeId())) {
            v.setSaleTypeId(getSaleType().get());
            modified = true;
        }

        return modified;
    }
}
