package com.ecep.contract.vm;

import java.util.Objects;

import com.ecep.contract.model.EmployeeRole;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class EmployeeRoleViewModel extends IdentityViewModel<EmployeeRole> {
    private SimpleStringProperty code = new SimpleStringProperty();
    private SimpleStringProperty name = new SimpleStringProperty();
    private SimpleBooleanProperty systemAdministrator = new SimpleBooleanProperty();
    private SimpleBooleanProperty manager = new SimpleBooleanProperty();
    private SimpleBooleanProperty active = new SimpleBooleanProperty();

    public static EmployeeRoleViewModel from(EmployeeRole v) {
        EmployeeRoleViewModel model = new EmployeeRoleViewModel();
        model.update(v);
        return model;
    }

    @Override
    protected void updateFrom(EmployeeRole v) {
        super.updateFrom(v);
        getCode().set(v.getCode());
        getName().set(v.getName());
        getSystemAdministrator().set(v.isSystemAdministrator());
        getManager().set(v.isManager());
        getActive().set(v.isActive());
    }

    @Override
    public boolean copyTo(EmployeeRole v) {
        boolean modified = super.copyTo(v);
        if (!Objects.equals(getCode().get(), v.getCode())) {
            v.setCode(getCode().get());
            modified = true;
        }
        if (!Objects.equals(getName().get(), v.getName())) {
            v.setName(getName().get());
            modified = true;
        }
        if (!Objects.equals(getSystemAdministrator().get(), v.isSystemAdministrator())) {
            v.setSystemAdministrator(getSystemAdministrator().get());
            modified = true;
        }
        if (!Objects.equals(getManager().get(), v.isManager())) {
            v.setManager(getManager().get());
            modified = true;
        }
        if (!Objects.equals(getActive().get(), v.isActive())) {
            v.setActive(getActive().get());
            modified = true;
        }

        return modified;
    }
}
