package com.ecep.contract.vm;

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

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

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

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

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

    private SimpleObjectProperty<LocalDateTime> loginTime = new SimpleObjectProperty<>();
    private SimpleObjectProperty<LocalDateTime> activeTime = new SimpleObjectProperty<>();


    public static EmployeeLoginHistoryViewModel from(EmployeeLoginHistory v) {
        EmployeeLoginHistoryViewModel vm = new EmployeeLoginHistoryViewModel();
        vm.update(v);
        return vm;
    }


    @Override
    protected void updateFrom(EmployeeLoginHistory v) {
        super.updateFrom(v);
        getIp().set(v.getIp());
        getMac().set(v.getMac());
        getEmployee().set(v.getEmployee());
        getLoginTime().set(v.getLoginTime());
        getActiveTime().set(v.getActiveTime());
    }

    @Override
    public boolean copyTo(EmployeeLoginHistory 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(getLoginTime().get(), v.getLoginTime())) {
            v.setLoginTime(getLoginTime().get());
            modified = true;
        }
        if (!Objects.equals(getActiveTime().get(), v.getActiveTime())) {
            v.setActiveTime(getActiveTime().get());
            modified = true;
        }
        return modified;
    }
}
