/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.model;

import java.security.NoSuchAlgorithmException;

import kr.co.zumo.app.lifeplus.util.StringUtil;

/**
 * PinModel
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 21.]   [최초 작성]
 * @since 2018. 9. 21.
 */
public class PinModel extends Model {

  /**
   * 입력한 핀과 저장된 핀이 같은지 확인
   *
   * @param pin "0000"
   * @return boolean
   */
  public boolean verifyPin(String pin) {
    String encryptedPin;
    try {
      encryptedPin = StringUtil.convertToSHA256(StringUtil.convertToMD5(pin));
    } catch (Exception e) {
      e.printStackTrace();
      encryptedPin = "";
    }
    String savedPin = SuperModel.getInstance().getPreferences().getEncryptedPin();

    return StringUtil.isFull(encryptedPin) && StringUtil.isFull(savedPin) && savedPin.equals(encryptedPin);
  }

  /**
   * 핀 저장
   *
   * @param pin
   */
  public void savePin(String pin) {
    SuperModel.getInstance().savePinWithEncryption(pin);
  }

  @Override
  protected void destroyInternal() {

  }

  @Override
  protected void startInternal() {

  }

  @Override
  protected void stopInternal() {

  }

  @Override
  protected void resumeInternal() {

  }

  @Override
  protected void pauseInternal() {

  }
}
