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 javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class EmployeeAuthBindViewModel extends IdentityViewModel<EmployeeAuthBind> implements EmployeeBasedViewModel {
    private SimpleStringProperty ip = new SimpleStringProperty();
    private SimpleStringProperty mac = new SimpleStringProperty();

    private SimpleObjectProperty<Employee> employee = new SimpleObjectProperty<>();

    private SimpleObjectProperty<LocalDateTime> createTime = new SimpleObjectProperty<>();

    private SimpleObjectProperty<Employee> updater = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> updateTime = new SimpleObjectProperty<>();

    private SimpleStringProperty description = new SimpleStringProperty();


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


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

    @Override
    public boolean copyTo(EmployeeAuthBind 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.getEmployee())) {
            v.setEmployee(getEmployee().get());
            modified = true;
        }
        if (!Objects.equals(getCreateTime().get(), v.getCreateTime())) {
            v.setCreateTime(getCreateTime().get());
            modified = true;
        }
        if (!Objects.equals(getUpdater().get(), v.getUpdater())) {
            v.setUpdater(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;
    }
}
