package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.ContractFileType;
import com.ecep.contract.vo.VendorGroupRequireFileTypeVo;

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

/**
 * 供应商组要求的文件类型视图模型
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class VendorGroupRequireFileTypeViewModel extends IdentityViewModel<VendorGroupRequireFileTypeVo> {
    private SimpleObjectProperty<Integer> groupId = new SimpleObjectProperty<>();
    private SimpleObjectProperty<ContractFileType> fileType = new SimpleObjectProperty<>();
    private SimpleObjectProperty<ContractFileType.Frequency> frequency = new SimpleObjectProperty<>();

    /**
     * 创建VendorGroupRequireFileTypeViewModel实例
     * 
     * @param v VendorGroupRequireFileTypeVo对象
     * @return VendorGroupRequireFileTypeViewModel实例
     */
    public static VendorGroupRequireFileTypeViewModel from(VendorGroupRequireFileTypeVo v) {
        VendorGroupRequireFileTypeViewModel vm = new VendorGroupRequireFileTypeViewModel();
        vm.update(v);
        return vm;
    }

    @Override
    protected void updateFrom(VendorGroupRequireFileTypeVo v) {
        super.updateFrom(v);
        getGroupId().set(v.getGroupId());
        getFileType().set(v.getFileType());
        getFrequency().set(v.getFrequency());
    }

    @Override
    public boolean copyTo(VendorGroupRequireFileTypeVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getGroupId().get(), v.getGroupId())) {
            v.setGroupId(getGroupId().get());
            modified = true;
        }
        if (!Objects.equals(getFileType().get(), v.getFileType())) {
            v.setFileType(getFileType().get());
            modified = true;
        }
        if (!Objects.equals(getFrequency().get(), v.getFrequency())) {
            v.setFrequency(getFrequency().get());
            modified = true;
        }
        return modified;
    }
}
