Imports System.ComponentModel
Imports System.Collections.ObjectModel

Public Class Alumno
  Implements INotifyPropertyChanged
  Private _idAlumno As Integer
  Public Property IdAlumno() As Integer
    Get
      Return _idAlumno
    End Get
    Set(value As Integer)
      _idAlumno = value
      OnPropertyChanged(New PropertyChangedEventArgs("IdAlumno"))
    End Set
  End Property

  Private _nomAlumno As String
  Public Property NomAlumno() As String
    Get
      Return _nomAlumno
    End Get
    Set(value As String)
      _nomAlumno = value
      OnPropertyChanged(New PropertyChangedEventArgs("NomAlumno"))
    End Set
  End Property

  Private _dirAlumno As String
  Public Property DirAlumno() As String
    Get
      Return _dirAlumno
    End Get
    Set(value As String)
      _dirAlumno = value
      OnPropertyChanged(New PropertyChangedEventArgs("DirAlumno"))
    End Set
  End Property

  Private _estAlumno As String
  Public Property EstAlumno() As String
    Get
      Return _estAlumno
    End Get
    Set(value As String)
      _estAlumno = value
      OnPropertyChanged(New PropertyChangedEventArgs("EstAlumno"))
    End Set
  End Property

  Private _becaAlumno As Boolean
  Public Property BecaAlumno() As Boolean
    Get
      Return _becaAlumno
    End Get
    Set(value As Boolean)
      _becaAlumno = value
      OnPropertyChanged(New PropertyChangedEventArgs("BecaAlumno"))
    End Set
  End Property

  Private _listaCoAsignaturas As ObservableCollection(Of Asignaturas)
  Public Property ListaCoAsignaturas() As ObservableCollection(Of Asignaturas)
    Get
      Return _listaCoAsignaturas
    End Get
    Set(value As ObservableCollection(Of Asignaturas))
      _listaCoAsignaturas = value
      OnPropertyChanged(New PropertyChangedEventArgs("ListaCoAsignaturas"))
    End Set
  End Property

  Private _listaAsigsObs As ObservableCollection(Of Asignatura)
  Public Property ListaAsigsObs() As ObservableCollection(Of Asignatura)
    Get
      _listaAsigsObs = ObtenerAsigsObsOps("Obligatorias")
      Return _listaAsigsObs
    End Get
    Set(value As ObservableCollection(Of Asignatura))
      _listaAsigsObs = value
      OnPropertyChanged(New PropertyChangedEventArgs("ListaAsigsObs"))
    End Set
  End Property

  Private _listaAsigsOps As ObservableCollection(Of Asignatura)
  Public Property ListaAsigsOps() As ObservableCollection(Of Asignatura)
    Get
      _listaAsigsOps = ObtenerAsigsObsOps("Optativas")
      Return _listaAsigsOps
    End Get
    Set(value As ObservableCollection(Of Asignatura))
      _listaAsigsOps = value
      OnPropertyChanged(New PropertyChangedEventArgs("ListaAsigsOps"))
    End Set
  End Property

  Private Function ObtenerAsigsObsOps(tipo As String) As ObservableCollection(Of Asignatura)
    If _listaCoAsignaturas IsNot Nothing Then
      For Each asigs As Asignaturas In _listaCoAsignaturas
        If asigs.Tipo = tipo Then
          Return asigs.ListaAsignaturas
        End If
      Next
    End If
    Return Nothing
  End Function

  Public Function ObtenerAsignatura(idAsig As Integer) As Asignatura
    Dim colAsigs As ObservableCollection(Of Asignatura)
    ' Obligatorias
    colAsigs = ListaAsigsObs
    If colAsigs IsNot Nothing Then
      For Each asig As Asignatura In colAsigs
        If asig.IdAsignatura = idAsig Then
          Return asig
        End If
      Next
    End If
    ' Optativas
    colAsigs = ListaAsigsOps
    If colAsigs IsNot Nothing Then
      For Each asig As Asignatura In colAsigs
        If asig.IdAsignatura = idAsig Then
          Return asig
        End If
      Next
    End If
    Return Nothing
  End Function

  Public Event PropertyChanged As PropertyChangedEventHandler _
    Implements INotifyPropertyChanged.PropertyChanged
  Public Sub OnPropertyChanged(e As PropertyChangedEventArgs)
    RaiseEvent PropertyChanged(Me, e)
    ' generar evento
  End Sub

  Public Overrides Function ToString() As String
    Return NomAlumno
  End Function

  Public Sub New()
    IdAlumno = 123
    NomAlumno = "¿Nombre?"
    DirAlumno = "¿Dirección?"
    EstAlumno = "¿Estudios?"
    BecaAlumno = False
    ListaCoAsignaturas = New ObservableCollection(Of Asignaturas)()
  End Sub

  Public Sub New(id As Integer, nom As String, dir As String, est As String, beca As Boolean, lista As ObservableCollection(Of Asignaturas))
    IdAlumno = id
    NomAlumno = nom
    DirAlumno = dir
    EstAlumno = est
    BecaAlumno = beca
    ListaCoAsignaturas = lista
  End Sub
End Class
