package com.casic.br.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.casic.br.R
import com.casic.br.model.SolutionModel

class FaultDescAdapter(
    val context: Context, private val dataRows: MutableList<SolutionModel>
) : RecyclerView.Adapter<FaultDescAdapter.ItemViewHolder>() {

    private var layoutInflater: LayoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        return ItemViewHolder(
            layoutInflater.inflate(R.layout.item_fault_desc_rv_l, parent, false)
        )
    }

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        val rowsModel = dataRows[position]
        holder.errorCodeView.text = rowsModel.errorCode
        holder.phenomenonView.text = rowsModel.phenomenon
        holder.solutionRecyclerView.adapter = SolutionAdapter(context, rowsModel.solution)
    }

    override fun getItemCount(): Int = dataRows.size

    class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val errorCodeView: TextView = itemView.findViewById(R.id.errorCodeView)
        val phenomenonView: TextView = itemView.findViewById(R.id.phenomenonView)
        val solutionRecyclerView: RecyclerView = itemView.findViewById(R.id.solutionRecyclerView)
    }
}