package com.ecep.contract.vm;

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

import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeAuthBind;

import com.ecep.contract.vo.EmployeeAuthBindVo;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class EmployeeAuthBindViewModel extends IdentityViewModel<EmployeeAuthBindVo> implements EmployeeBasedViewModel {
    private SimpleStringProperty ip = new SimpleStringProperty();
    private SimpleStringProperty mac = new SimpleStringProperty();
    /**
     * Employee
     */
    private SimpleObjectProperty<Integer> employee = new SimpleObjectProperty<>();

    private SimpleObjectProperty<LocalDateTime> createTime = new SimpleObjectProperty<>();
    /**
     * Employee
     */
    private SimpleObjectProperty<Integer> updater = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> updateTime = new SimpleObjectProperty<>();

    private SimpleStringProperty description = new SimpleStringProperty();


    public static EmployeeAuthBindViewModel from(EmployeeAuthBindVo v) {
        EmployeeAuthBindViewModel vm = new EmployeeAuthBindViewModel();
        vm.update(v);
        return vm;
    }


    @Override
    protected void updateFrom(EmployeeAuthBindVo v) {
        super.updateFrom(v);
        getIp().set(v.getIp());
        getMac().set(v.getMac());
        getEmployee().set(v.getEmployeeId());
        getCreateTime().set(v.getCreateTime());
        getUpdater().set(v.getUpdaterId());
        getUpdateTime().set(v.getUpdateTime());
        getDescription().set(v.getDescription());
    }

    @Override
    public boolean copyTo(EmployeeAuthBindVo v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getIp().get(), v.getIp())) {
            v.setIp(getIp().get());
            modified = true;
        }
        if (!Objects.equals(getMac().get(), v.getMac())) {
            v.setMac(getMac().get());
            modified = true;
        }
        if (!Objects.equals(getEmployee().get(), v.getEmployeeId())) {
            v.setEmployeeId(getEmployee().get());
            modified = true;
        }
        if (!Objects.equals(getCreateTime().get(), v.getCreateTime())) {
            v.setCreateTime(getCreateTime().get());
            modified = true;
        }
        if (!Objects.equals(getUpdater().get(), v.getUpdaterId())) {
            v.setUpdaterId(getUpdater().get());
            modified = true;
        }
        if (!Objects.equals(getUpdateTime().get(), v.getUpdateTime())) {
            v.setUpdateTime(getUpdateTime().get());
            modified = true;
        }
        if (!Objects.equals(getDescription().get(), v.getDescription())) {
            v.setDescription(getDescription().get());
            modified = true;
        }
        return modified;
    }
}
