local CoppaUtil = {}
local getCoppaState = function()
  return CS.GameEntry.Setting:GetString(CS.KWSVerification.CoppaPrefsKeys.COPPA_STATE, CS.KWSVerification.CoppaState.NonUsRegions)
end
local getAccountState = function()
  local accountState = CS.GameEntry.Setting:GetInt(CS.KWSVerification.CoppaPrefsKeys.ACCOUNT_STATE, CS.KWSVerification.AccountState.NotVerified)
  return accountState
end
local isCertifiedChildren = function()
  return getCoppaState() == CS.KWSVerification.CoppaState.UsCertifiedChildren
end

function CoppaUtil.IsCoppaLimit()
  local accountState = getAccountState()
  if accountState == CS.KWSVerification.AccountState.Adult then
    return false
  elseif accountState == CS.KWSVerification.AccountState.Child then
    return true
  else
    return isCertifiedChildren()
  end
end

function CoppaUtil.GetCoppaDialogId()
  return "coppa_limit_tips"
end

function CoppaUtil.IsCoppaLimitWithTips()
  if CoppaUtil.IsCoppaLimit() then
    UIUtil.ShowTipsId(CoppaUtil.GetCoppaDialogId())
    return true
  end
  return false
end

function CoppaUtil.IsShowCoppaBtnInMainUI()
  if DataCenter.BuildManager.MainLv < 1 then
    return false
  end
  return CoppaUtil.CanAppeal() or CoppaUtil.NeedVerify()
end

function CoppaUtil.CanAppeal()
  return CoppaUtil.IsCoppaLimit()
end

function CoppaUtil.NeedVerify()
  local accountState = getAccountState()
  if accountState == CS.KWSVerification.AccountState.Adult or accountState == CS.KWSVerification.AccountState.Child then
    return false
  end
  local state = getCoppaState()
  return state == CS.KWSVerification.CoppaState.UsUncertifiedNewPlayer or state == CS.KWSVerification.CoppaState.UsUncertifiedNeedMail or state == CS.KWSVerification.CoppaState.UsUncertifiedMailPending or state == CS.KWSVerification.CoppaState.UsUncertifiedOldPlayer or state == CS.KWSVerification.CoppaState.UsUncertifiedOldTimeOut
end

function CoppaUtil.OpenVerifyDialog()
  CS.GameEntry.Setting:SetString(CS.KWSVerification.CoppaPrefsKeys.OPEN_FROM, CS.KWSVerification.CoppaOpenFrom.MainUI)
  CS.PrivacyFuncUtil.Instance:ShowUIPrivacyUS(0)
end

function CoppaUtil.PopupVerifyDialog()
  CS.GameEntry.Setting:SetString(CS.KWSVerification.CoppaPrefsKeys.OPEN_FROM, CS.KWSVerification.CoppaOpenFrom.Popup)
  CS.PrivacyFuncUtil.Instance:ShowUIPrivacyUS(0)
end

function CoppaUtil.Coppa_HandleSecondVerify_IpCountry()
  return CS.PrivacyFuncUtil.Instance:Coppa_HandleSecondVerify_IpCountry()
end

function CoppaUtil.GetFinalConfirmTime()
  return CS.PrivacyFuncUtil.Instance:GetFinalConfirmTime()
end

return ConstClass("CoppaUtil", CoppaUtil)
