package com.example.features.notification.controller

import android.app.PendingIntent
import android.util.TypedValue
import android.view.View
import android.widget.RemoteViews

class NotificationRemoteViewsBuilder(
    private val packageName: String,
    private val layoutIdAboveAndroid12: Int,
    private val layoutIdBelowAndroid12: Int
) {
    private var remoteViews: RemoteViews = RemoteViews(
        packageName, if (android.os.Build.VERSION.SDK_INT >= 31) {
            layoutIdAboveAndroid12
        } else {
            layoutIdBelowAndroid12
        }
    )

    fun setViewVisible(viewId: Int, isVisible:Boolean): NotificationRemoteViewsBuilder {
        remoteViews.setViewVisibility(viewId, if (isVisible) View.VISIBLE else View.GONE)
        return this
    }

    fun setTextViewText(viewId: Int, text: CharSequence): NotificationRemoteViewsBuilder {
        remoteViews.setTextViewText(viewId, text)
        return this
    }

    fun setTextViewTextSize(viewId: Int, size: Float): NotificationRemoteViewsBuilder {
        remoteViews.setTextViewTextSize(viewId, TypedValue.COMPLEX_UNIT_SP, size)
        return this
    }

    fun setImageViewResource(viewId: Int, resId: Int): NotificationRemoteViewsBuilder {
        remoteViews.setImageViewResource(viewId, resId)
        return this
    }


    fun setOnClickPendingIntent(viewId: Int, pendingIntent: PendingIntent): NotificationRemoteViewsBuilder {
        remoteViews.setOnClickPendingIntent(viewId, pendingIntent)
        return this
    }

    fun build(): RemoteViews {
        return remoteViews
    }
}