package kr.co.hanwha.hifive.screen.common;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import kr.co.hanwha.hifive.HFApplication;
import kr.co.hanwha.hifive.base.BaseActivity;
import kr.co.hanwha.hifive.data.model.NotificationData;
import kr.co.hanwha.hifive.enums.BaseAnimationType;
import kr.co.hanwha.hifive.enums.BaseToolbarType;
import kr.co.hanwha.hifive.screen.intro.CheckAuthNumberActivity;
import kr.co.hanwha.hifive.screen.intro.IntroActivity;
import kr.co.hanwha.hifive.util.HFActivityUtil;
import kr.co.hanwha.hifive.util.HFInfoUtil;
import kr.co.hanwha.hifive.util.HFNotiUtil;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;

public class LandingActivity extends BaseActivity {
    @Override
    protected int getContentViewResource() {
        return 0;
    }

    @Override
    protected BaseToolbarType isToolbarStyle() {
        return null;
    }

    @Override
    protected BaseAnimationType isShowActivityAnimation() {
        return null;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String group_id = getIntent().getStringExtra(HFNotiUtil.KEY_GROUP_ID);
        String title = getIntent().getStringExtra(HFNotiUtil.KEY_TITLE);
        String message = getIntent().getStringExtra(HFNotiUtil.KEY_MESSAGE);
        String type = getIntent().getStringExtra(HFNotiUtil.KEY_TYPE);
        String value1 = getIntent().getStringExtra(HFNotiUtil.KEY_VALUE1);
        String value2 = getIntent().getStringExtra(HFNotiUtil.KEY_VALUE2);
        String value3 = getIntent().getStringExtra(HFNotiUtil.KEY_VALUE3);
        String db_code = getIntent().getStringExtra(HFNotiUtil.KEY_DB_CODE);

        boolean isEqualDepartment = HFInfoUtil.getDepartmentCode(this).equals(db_code);
        if (isEqualDepartment == false) {
            HFInfoUtil.setMemberLoginId(this, "");
        }

        if (HFApplication.getActivityCount() > 1 &&
                HFApplication.getRunningActivity() instanceof IntroActivity == false &&
                HFApplication.getRunningActivity() instanceof CheckAuthNumberActivity == false &&
                isEqualDepartment) {
            NotificationData data = new NotificationData(group_id, title, message, type, value1, value2, value3, db_code);
            HFNotiUtil.pendingNotification(this, data);
            finish();
        } else {
            Intent intent = new Intent(getApplicationContext(), IntroActivity.class);
            if (TextUtils.isEmpty(group_id) == false)
                intent.putExtra(HFNotiUtil.KEY_GROUP_ID, group_id);
            if (TextUtils.isEmpty(type) == false)
                intent.putExtra(HFNotiUtil.KEY_TYPE, type);
            if (TextUtils.isEmpty(value1) == false)
                intent.putExtra(HFNotiUtil.KEY_VALUE1, value1);
            if (TextUtils.isEmpty(value2) == false)
                intent.putExtra(HFNotiUtil.KEY_VALUE2, value2);
            if (TextUtils.isEmpty(value3) == false)
                intent.putExtra(HFNotiUtil.KEY_VALUE3, value3);
            if (TextUtils.isEmpty(db_code) == false)
                intent.putExtra(HFNotiUtil.KEY_DB_CODE, db_code);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            finish();
        }
    }
}
