package com.reallinkbilling.jspRedirect;



import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.reallinkbilling.resource.GetListResource;
import com.reallinkbilling.view.ViewGodownList;


//import com.stonecrusher.view.ViewGodownList;
import com.opensymphony.xwork2.ActionSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class GodownManagementJsp extends ActionSupport implements SessionAware {

    private static final long serialVersionUID = 1L;
    private SessionMap<String, Object> sessionMap;
    private HashMap<String, String> emplyeeList = new HashMap<String, String>();
    private ArrayList<String> godwnTypeList = new ArrayList<String>();
    private String godownType;
    private String godownManager;
    private ArrayList<HashMap<String, String>> godownList = new ArrayList<HashMap<String, String>>();

    public String execute() {
        String result = "login";

        if (this.getSessionMap() == null || this.getSessionMap().get("login") == null) {
            addActionMessage("Please Logout and Login again!");
            result = "login";
        } else {
            // Load employee list
            this.setEmplyeeList(GetListResource.getEmplyeeList(this.getSessionMap(), "SUPERVISOR"));

            // Load godown types
//            this.getGodwnTypeList().add("RENTED");
//            this.getGodwnTypeList().add("OWNED");
//            this.getGodwnTypeList().add("FREE OF COST");

            // Set default values
//            this.setGodownType("OWNED");
//            this.setGodownManager("");

            // Load existing godowns
            ViewGodownList viewGodownList = new ViewGodownList();
            viewGodownList.setSessionMap(this.getSessionMap());
            String viewResult = viewGodownList.execute();
            
            if (viewResult.equals(SUCCESS)) {
                this.setGodownList(viewGodownList.getGodownList());
            }

            result = SUCCESS;
        }
        return result;
    }

    public HashMap<String, String> getEmplyeeList() {
        return emplyeeList;
    }

    public void setEmplyeeList(HashMap<String, String> emplyeeList) {
        this.emplyeeList = emplyeeList;
    }

    public ArrayList<String> getGodwnTypeList() {
        return godwnTypeList;
    }

    public void setGodwnTypeList(ArrayList<String> godwnTypeList) {
        this.godwnTypeList = godwnTypeList;
    }

    public String getGodownType() {
        return godownType;
    }

    public void setGodownType(String godownType) {
        this.godownType = godownType;
    }

    public String getGodownManager() {
        return godownManager;
    }

    public void setGodownManager(String godownManager) {
        this.godownManager = godownManager;
    }

    public ArrayList<HashMap<String, String>> getGodownList() {
        return godownList;
    }

    public void setGodownList(ArrayList<HashMap<String, String>> godownList) {
        this.godownList = godownList;
    }

    public SessionMap<String, Object> getSessionMap() {
        return sessionMap;
    }

    public void setSessionMap(SessionMap<String, Object> sessionMap) {
        this.sessionMap = sessionMap;
    }

    @Override
    public void setSession(Map<String, Object> map) {
        sessionMap = (SessionMap<String, Object>) map;
    }
}