package kr.co.hanwha.hifive.util;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.enums.MessageType;
import kr.co.hanwha.hifive.enums.ProjectEvaluationType;
import kr.co.hanwha.hifive.enums.TaskEvaluationType;
import kr.co.hanwha.hifive.enums.TaskStatusType;

/**
 * Created by sanghoonkwon on 2018. 1. 25..
 */

public class HFTaskUtil {
    private static final int DUEDATE_COLOR = 3;

    public static int getDueDateFontColor(Context context, String due_to, String server_time) {
        int d_day = HFDateUtil.getCalculateDDayFromToday(due_to, HFDateUtil.FORMAT_TASK_DUEDATE_SERVER);
        if (d_day > DUEDATE_COLOR) return HFCommonUtil.getColor(context, R.color.hf_grey01);
        else
            return HFCommonUtil.getColor(context, R.color.hf_red06);
    }

    /**
     * 메인 - 기한(날짜) : 아이콘
     *
     * @param context     Context
     * @param due_to      기한
     * @param server_time 서버 시간
     * @return 아이콘
     */
    public static Drawable getDueDateIconDrawable(Context context, String due_to, String server_time) {
        int d_day = HFDateUtil.getCalculateDDayFromToday(due_to, HFDateUtil.FORMAT_TASK_DUEDATE_SERVER);
        if (d_day > DUEDATE_COLOR) return context.getResources().getDrawable(R.mipmap.ic_date_gray);
        else
            return context.getResources().getDrawable(R.mipmap.ic_date_org);
    }

    /**
     * 메인 - 기한(날짜) : 텍스트
     * <p>
     * D-DAY 표시 정책 <br>
     * http://www.junstarok.com/redmine/issues/292<br>
     *
     * @param context     Context
     * @param due_to      기한
     * @param server_time 서버 시간
     * @return 텍스트
     */
    public static String getDueDateText(Context context, String due_to, String server_time) {
        String dayStr = "";
        int d_day = HFDateUtil.getCalculateDDayFromToday(due_to, HFDateUtil.FORMAT_TASK_DUEDATE_SERVER);
        if (d_day == 0)
            dayStr = context.getString(R.string.task_main_duedate_today);
        else if (d_day == 1)
            dayStr = context.getString(R.string.task_main_duedate_tomorrow);
        else if (d_day > 0)
            dayStr = String.format(context.getString(R.string.task_main_duedate_left), d_day);
        else
            dayStr = String.format(context.getString(R.string.task_main_duedate_over), -d_day);

        return dayStr;
    }

    /**
     * 메인 - 기한(날짜) : 진행 / 완료 폰트 색상
     *
     * @param context Context
     * @param status  TASK 상태
     * @return 칼라
     */
    public static int getDueDateFontColor(Context context, int status) {
        if (status == TaskStatusType.CLOSED.getCode())
            return HFCommonUtil.getColor(context, R.color.hf_grey04);
        else
            return HFCommonUtil.getColor(context, R.color.hf_red03);
    }

    /**
     * 메인 - 작성자 이름 : 진행 / 완료 폰트 색상
     *
     * @param context Context
     * @param status  TASK 상태
     * @return 칼라
     */
    public static int getNameFontColor(Context context, int status) {
        if (status == TaskStatusType.CLOSED.getCode())
            return HFCommonUtil.getColor(context, R.color.hf_grey04);
        else
            return HFCommonUtil.getColor(context, R.color.hf_grey01);
    }

    /**
     * 메인 - TASK 명 : 진행 / 완료 폰트 색상
     *
     * @param context Context
     * @param status  TASK 상태
     * @return 칼라
     */
    public static int getTaskFontColor(Context context, int status) {
        if (status == TaskStatusType.CLOSED.getCode())
            return HFCommonUtil.getColor(context, R.color.hf_grey04);
        else
            return HFCommonUtil.getColor(context, R.color.hf_grey02);
    }

    /**
     * 메인 - 할일 / 요청함 - 상태 표시 폰트 색상
     *
     * @param context Context
     * @param status  TASK 상태
     * @return 칼라
     */
    public static int getStatusFontColor(@NonNull Context context, @NonNull int status) {
        if (status == TaskStatusType.ASSIGNED.getCode() ||
                status == TaskStatusType.DOING_TODAY.getCode() ||
                status == TaskStatusType.EVALUATED.getCode() ||
                status == TaskStatusType.REQUESTED.getCode()) {
            return HFCommonUtil.getColor(context, R.color.hf_olive_green01);
        } else if (status == TaskStatusType.REJECTED_REQUEST.getCode() ||
                status == TaskStatusType.REJECTED_EVALUATION.getCode())
            return HFCommonUtil.getColor(context, R.color.hf_orange01);
        else if (status == TaskStatusType.CLOSED.getCode())
            return HFCommonUtil.getColor(context, R.color.hf_grey15);

        return HFCommonUtil.getColor(context, R.color.hf_olive_green01);
    }

    /**
     * 메인 - 할일 / 요청함 - 상태 표시 폰트 배경 색상
     *
     * @param context Context
     * @param status  TASK 상태
     * @return 칼라
     */
    public static Drawable getStatusBackground(@NonNull Context context, @NonNull int status) {
        if (status == TaskStatusType.ASSIGNED.getCode() ||
                status == TaskStatusType.DOING_TODAY.getCode() ||
                status == TaskStatusType.EVALUATED.getCode() ||
                status == TaskStatusType.REQUESTED.getCode()) {
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_olivegreen03);
        } else if (status == TaskStatusType.REJECTED_REQUEST.getCode() ||
                status == TaskStatusType.REJECTED_EVALUATION.getCode())
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_orange03);
        else if (status == TaskStatusType.CLOSED.getCode())
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_grey17);

        return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_grey17);
    }

    /**
     * 메인 - 할일 / 요청함 - 상태 표시 텍스트
     *
     * @param context Context
     * @param status  TASK 상태
     * @return 텍스트
     */
    public static String getRequestStatusText(@NonNull Context context, @NonNull int status, @Nullable int evaluation) {
        String statusStr = "";
        if (status == TaskStatusType.ASSIGNED.getCode() ||
                status == TaskStatusType.DOING_TODAY.getCode())
            statusStr = context.getString(R.string.task_main_task_status_assigned);
        else if (status == TaskStatusType.REQUESTED.getCode())
            statusStr = context.getString(R.string.task_main_task_status_requested);
        else if (status == TaskStatusType.REJECTED_REQUEST.getCode())
            statusStr = context.getString(R.string.task_main_task_status_rejected_request);
        else if (status == TaskStatusType.EVALUATED.getCode())
            statusStr = context.getString(R.string.task_main_task_status_evaluated);
        else if (status == TaskStatusType.REJECTED_EVALUATION.getCode())
            statusStr = context.getString(R.string.task_main_task_status_rejected_evaluation);
        else if (status == TaskStatusType.CLOSED.getCode()) {
            if (evaluation == TaskEvaluationType.CANCELED.getCode())
                statusStr = context.getString(R.string.task_main_task_status_closed_canceled);
            else statusStr = context.getString(R.string.task_main_task_status_closed);
        }
        return statusStr;
    }


    /**
     * TASK 상세 - 댓글 상태 표시 배경 색상
     *
     * @param context Context
     * @param type    MessageType
     * @return 칼라
     */
    public static Drawable getStatusMessageBackground(@NonNull Context context, @NonNull int type) {
        if (type == MessageType.COMMENT.getCode()) {

        } else if (type == MessageType.REJECT_REQUEST.getCode()) {
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_orange03);
        } else if (type == MessageType.TRANSFER.getCode()) {
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_grey17);
        } else if (type == MessageType.REJECT_EVALUATION.getCode()) {
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_orange03);
        }

        return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_grey17);
    }

    /**
     * TASK 상세 - 댓글 상태 표시 폰트 색상
     *
     * @param context Context
     * @param type    MessageType
     * @return 칼라
     */
    public static int getStatusMessageFontColor(@NonNull Context context, @NonNull int type) {
        if (type == MessageType.COMMENT.getCode()) {

        } else if (type == MessageType.REJECT_REQUEST.getCode()) {
            return HFCommonUtil.getColor(context, R.color.hf_orange01);
        } else if (type == MessageType.TRANSFER.getCode()) {
            return HFCommonUtil.getColor(context, R.color.hf_grey15);
        } else if (type == MessageType.REJECT_EVALUATION.getCode()) {
            return HFCommonUtil.getColor(context, R.color.hf_orange01);
        }

        return HFCommonUtil.getColor(context, R.color.hf_grey15);
    }

    /**
     * TASK 상세 - 댓글 상태 표시 텍스트
     *
     * @param context Context
     * @param type    MessageType
     * @return 텍스트
     */
    public static String getStatusMessageText(@NonNull Context context, @NonNull int type) {
        String statusStr = "";

        if (type == MessageType.COMMENT.getCode()) {

        } else if (type == MessageType.REJECT_REQUEST.getCode()) {
            statusStr = context.getString(R.string.task_detail_status_reject);
        } else if (type == MessageType.TRANSFER.getCode()) {
            statusStr = context.getString(R.string.task_detail_status_transfer);
        } else if (type == MessageType.REJECT_EVALUATION.getCode()) {
            statusStr = context.getString(R.string.task_detail_status_eval_reject);
        }

        return statusStr;
    }

    /**
     * TASK 상세 - 댓글 상태 표시 여부
     *
     * @param context Context
     * @param type    MessageType
     * @return Boolean
     */
    public static boolean getStatusMessageVisibility(@NonNull Context context, @NonNull int type) {
        if (type == MessageType.COMMENT.getCode()) {

        } else if (type == MessageType.REJECT_REQUEST.getCode()) {
            return true;
        } else if (type == MessageType.TRANSFER.getCode()) {
            return true;
        } else if (type == MessageType.REJECT_EVALUATION.getCode()) {
            return true;
        }

        return false;
    }

    /**
     * PROJECT - 진행상황 칼라값
     *
     * @param context    Context
     * @param evaluation PROEJCT 상태
     * @return 칼라
     */
    public static Drawable getProjectStatusBackground(@NonNull Context context, @NonNull int evaluation) {
        if (evaluation == ProjectEvaluationType.GREEN.getCode())
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_evaluation_green);
        else if (evaluation == ProjectEvaluationType.YELLOW.getCode())
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_evaluation_yellow);
        else if (evaluation == ProjectEvaluationType.YELLOW_DOUBLE.getCode())
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_evaluation_yellow);
        else if (evaluation == ProjectEvaluationType.RED.getCode())
            return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_evaluation_red);
        return context.getResources().getDrawable(R.drawable.rounded_rectangle_status_evaluation_green);
    }

    /**
     * PROJECT - 진행상황 칼라값(ISSUE - Top)
     *
     * @param context    Context
     * @param evaluation PROEJCT 상태
     * @return 칼라
     */
    public static Drawable getProjectIssueTopBackground(@NonNull Context context, @NonNull int evaluation) {
        if (evaluation == ProjectEvaluationType.GREEN.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_green_top);
        else if (evaluation == ProjectEvaluationType.YELLOW.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_yellow_top);
        else if (evaluation == ProjectEvaluationType.YELLOW_DOUBLE.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_yellow_top);
        else if (evaluation == ProjectEvaluationType.RED.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_red_top);
        return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_green_top);
    }

    /**
     * PROJECT - 진행상황 칼라값(ISSUE - Bottom)
     *
     * @param context    Context
     * @param evaluation PROEJCT 상태
     * @return 칼라
     */
    public static Drawable getProjectIssueBottomBackground(@NonNull Context context, @NonNull int evaluation) {
        if (evaluation == ProjectEvaluationType.GREEN.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_green_bottom);
        else if (evaluation == ProjectEvaluationType.YELLOW.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_yellow_bottom);
        else if (evaluation == ProjectEvaluationType.YELLOW_DOUBLE.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_yellow_bottom);
        else if (evaluation == ProjectEvaluationType.RED.getCode())
            return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_red_bottom);
        return context.getResources().getDrawable(R.drawable.box_rounded_campaign_bg_green_bottom);
    }
}

