/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package admin;

import entities.CurrentSubject;
import entities.Lesson;
import entities.Users;
import helper.LessonType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import manager.LessionSessionBeanRemote;
import manager.UserSessionBeanRemote;

/**
 *
 * @author Szilárd
 */
@ManagedBean(name="CreateLesson")
@RequestScoped
public class CreateLesson {
    @EJB
    private LessionSessionBeanRemote lessionSessionBean;
    @EJB
    private UserSessionBeanRemote userSessionBean;

    CurrentSubject currentSubject;
    Lesson lesson;
    Users user;
    ArrayList<SelectItem> listTeachers;
    String type, type2, limit;
    Long teacherId;

    public CreateLesson() {
        Map m = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        this.currentSubject = (CurrentSubject) m.get("currentsubject");
        type = (String) m.get("type");
        type2 = (type.equals("Lecture")) ? "Előadás" : "Gyakorlat";

        lesson = new Lesson();
        lesson.setLessonType( (type.equals("Lecture")) ? LessonType.LECTURE : LessonType.PRACTICE );

    }

    public Lesson getLesson() {
        return lesson;
    }

    public void setLesson(Lesson lesson) {
        this.lesson = lesson;
    }

    public CurrentSubject getCurrentSubject() {
        return currentSubject;
    }

    public void setCurrentSubject(CurrentSubject currentSubject) {
        this.currentSubject = currentSubject;
    }

    public String getType2() {
        return type2;
    }

    public void setType2(String type2) {
        this.type2 = type2;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public Long getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(Long teacherId) {
        this.teacherId = teacherId;
    }

    
    
    public ArrayList getListTeachers() {
        List<Users> teachers = this.userSessionBean.findTeacher();
        listTeachers = new ArrayList();
        for(Users akt: teachers){
            listTeachers.add(new SelectItem(akt.getId(),akt.getName()));
        }
        return listTeachers;
    }

    public void setListTeachers(ArrayList listTeachers) {
        this.listTeachers = listTeachers;
    }

    


    public String backAction(){
        return "createsubject.jsp";
    }

    public String saveAction(){
        lesson.setRegistered(0);
        lesson.setCurrentSubjectId(currentSubject);
        lesson.setTeacherId(this.userSessionBean.findById(teacherId));
        this.lessionSessionBean.newLesson(lesson);
        return "createsubject.jsp";
    }

}
