package com.ecep.contract.vm;

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

import com.ecep.contract.model.DeliverySignMethod;
import com.ecep.contract.model.ProjectSaleType;

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<DeliverySignMethod> {
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty description = new SimpleStringProperty();
    private SimpleObjectProperty<LocalDate> created = new SimpleObjectProperty<>();

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

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

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

    @Override
    public boolean copyTo(DeliverySignMethod 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.getSaleType())) {
            v.setSaleType(getSaleType().get());
            modified = true;
        }

        return modified;
    }
}
