package kz.arta.synergy.workflow.mobile.android.common.utils;

import android.app.Activity;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

import kz.arta.synergy.workflow.mobile.android.R;
import kz.arta.synergy.workflow.mobile.android.works.models.WorkItem;

/**
 * Created by neox on 02.07.14.
 * Класс используется для проверки статуса работы
 */
public class StatusWork {

    /**
     * Активити
     */
    private Activity activity;

    /**
     * Статус работы
     */
    private TextView status;

    /**
     * Текущий прогресс работы (лейбл)
     */
    private TextView progressTitle;

    /**
     * Текущий прогресс работы
     */
    private SeekBar progress;

    /**
     * Метод отвечает за проверку и отображение типа работы (завершено, согласовано и т. д.)
     *
     * @param work - сама работа
     */
    public void checkStatus(WorkItem work) {
        switch (work.getWork_state_label()) {
            case "agreement":
                switch (work.getWork_state_icon()) {
                    case "progress_mfa_icon":
                        setTextTypeWork(activity.getString(R.string.on_agreement_full));
                        break;
                    case "progress_done_icon":
                        setTextTypeWork(activity.getString(R.string.agreement_done));
                        break;
                    case "progress_denied_icon":
                        setTextTypeWork(activity.getString(R.string.not_agreement));
                        break;
                    case "progress_deleted_icon":
                        setTextTypeWork(activity.getString(R.string.deleted));
                        break;
                }
                break;
            case "approval":
                switch (work.getWork_state_icon()) {
                    case "progress_mfa_icon":
                        setTextTypeWork(activity.getString(R.string.on_approval_full));
                        break;
                    case "progress_done_icon":
                        setTextTypeWork(activity.getString(R.string.approval_done));
                        break;
                    case "progress_denied_icon":
                        setTextTypeWork(activity.getString(R.string.not_approved));
                        break;
                    case "progress_deleted_icon":
                        setTextTypeWork(activity.getString(R.string.deleted));
                        break;
                }
                break;
            case "acquaintance":
                if (work.getWork_state_icon().equals("progress_mfa_icon")) {
                    setTextTypeWork(activity.getString(R.string.on_acquaintance_full));
                } else if (work.getWork_state_icon().equals("progress_done_icon")) {
                    setTextTypeWork(activity.getString(R.string.acquaintance_done));
                }
                break;
            case "progress":
                if (work.getWork_state_icon().equals("progress_done_icon")) {
                    setTextTypeWork(activity.getString(R.string.finished));
                }
                break;
            case "resolution-action":
                if (work.getWork_state_icon().equals("progress_resolution_icon")) {
                    setTextTypeWork(activity.getString(R.string.on_review_full));
                } else if (work.getWork_state_icon().equals("progress_resolution_done_icon") && work.getIs_resolution().equals("true")) {
                    setTextTypeWork(activity.getString(R.string.resolution_accepted));
                } else if (work.getWork_state_icon().equals("progress_resolution_done_icon") && !work.getIs_resolution().equals("true")) {
                    setTextTypeWork(activity.getString(R.string.deleted));
                } else if (work.getWork_state_icon().equals("progress_done_icon")) {
                    setTextTypeWork(activity.getString(R.string.finished));
                }
                break;
            case "registration":
                switch (work.getWork_state_icon()) {
                    case "progress_mfa_icon":
                        setTextTypeWork(activity.getString(R.string.on_registered_full));
                        break;
                    case "progress_deleted_icon":
                        setTextTypeWork(activity.getString(R.string.deleted));
                        break;
                    case "progress_done_icon":
                        setTextTypeWork(activity.getString(R.string.registered));
                        break;
                    case "progress_denied_icon":
                        setTextTypeWork(activity.getString(R.string.not_registered));
                        break;
                }
                break;
        }
    }

    /**
     * Метод отвечает за отображение панели с прогрессом
     *
     * @param text - текст типа работы
     */
    private void setTextTypeWork(String text) {
        if (status == null) {
            return;
        }
        status.setText(text);
        status.setVisibility(View.VISIBLE);
        if (progress != null) {
            progress.setVisibility(View.GONE);
        }
        if (progressTitle != null) {
            progressTitle.setVisibility(View.GONE);
        }
    }

    public void setStatusWork(TextView status) {
        this.status = status;
    }

    public Activity getActivity() {
        return activity;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    public void setProgressText(TextView progressTitle) {
        this.progressTitle = progressTitle;
    }

    public void setSeekBar(SeekBar progress) {
        this.progress = progress;
    }
}
