package com.rera.mss.model

import com.rera.mss.config.LONG_STRING_FIELD_LENGTH
import com.rera.mss.config.MEDIUM_STRING_FIELD_LENGTH
import javax.persistence.*
import javax.validation.constraints.NotBlank
import javax.validation.constraints.Size


@Entity
@Table(name = "PV_panel")
data class PvPanel(
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        var id: Long = 0,

        @NotBlank
        var efficiency: Float,

        @Size(max = LONG_STRING_FIELD_LENGTH)
        var manufacturer: String,

        @Size(max = MEDIUM_STRING_FIELD_LENGTH)
        var material: String
) {
    @OneToMany(mappedBy = "pvPanel", cascade = [CascadeType.ALL], orphanRemoval = true)
    var pvPanelAreas: MutableSet<PvPanelArea> = mutableSetOf()

    fun addPvPanelArea(pvPanelArea: PvPanelArea) {
        val pvPanelArea = PvPanelArea(
                pvPanel = this,
                monitoredArea = pvPanelArea.monitoredArea,
                area = pvPanelArea.area,
                altitude = pvPanelArea.altitude,
                tilt = pvPanelArea.tilt,
                direction = pvPanelArea.direction
        )
        pvPanelAreas.add(pvPanelArea)

    }
}