package com.abm.mainet.water.ui.model;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.abm.mainet.common.ui.model.AbstractFormModel;
import com.abm.mainet.common.utility.UserSession;
import com.abm.mainet.water.dto.ChangeOfOwnershipDTO;
import com.abm.mainet.water.service.ChangeOfOwnerShipService;

/**
 * @author Vivek.Kumar
 * @since 15 June 2016
 */
@Component
@Scope("session")
public class ExecuteChangeOfOwnerModel extends AbstractFormModel {

    private static final long serialVersionUID = -6862654165271451201L;

    private ChangeOfOwnershipDTO ownerDTO;

    @Autowired
    private ChangeOfOwnerShipService changeOfOwnerShipService;

    @Override
    public boolean saveForm() {

        boolean status = false;
        getOwnerDTO().setUpdatedBy(UserSession.getCurrent().getEmployee().getEmpId());
        status = changeOfOwnerShipService.executeChangeOfOwnership(getOwnerDTO());
        setSuccessMessage(
                status == true ? getAppSession().getMessage("water.approve") : getAppSession().getMessage("water.approve.fail"));
        return status;
    }

    public ChangeOfOwnershipDTO getOwnerDTO() {
        return ownerDTO;
    }

    public void setOwnerDTO(final ChangeOfOwnershipDTO ownerDTO) {
        this.ownerDTO = ownerDTO;
    }

}
