/* This Source Code Form is subject to the terms of the Mozilla Public
   License, v. 2.0. If a copy of the MPL was not distributed with this
   file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.components

import android.content.Context
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status
import mozilla.components.feature.sitepermissions.SitePermissionsStorage

class Storage(private val context: Context) {

    private val permissionsStorage by lazy {
        SitePermissionsStorage(context)
    }

    fun addSitePermissionException(
        origin: String,
        location: Status,
        notification: Status,
        microphone: Status,
        camera: Status
    ): SitePermissions {
        val sitePermissions = SitePermissions(
            origin = origin,
            location = location,
            camera = camera,
            microphone = microphone,
            notification = notification,
            savedAt = System.currentTimeMillis()
        )
        permissionsStorage.save(sitePermissions)
        return sitePermissions
    }

    fun findSitePermissionsBy(origin: String): SitePermissions? {
        return permissionsStorage.findSitePermissionsBy(origin)
    }

    fun updateSitePermissions(sitePermissions: SitePermissions) {
        permissionsStorage.update(sitePermissions)
    }
}
