package orm

import (
	"errors"

	"github.com/jinzhu/gorm"
)

type Class struct {
	gorm.Model
	Name          string
	CoordinatorID uint `schema:"coordinator_id"`
	MinuterID     uint `schema:"minuter_id"`
	Coordinator   Teacher
	Minuter       Teacher
	Teachers      []Teacher
	Students      []Student
}

func (t *Class) Create(db *gorm.DB, record map[string]interface{}) error {
	result := new(Class)

	if name := record["name"]; name == nil {
		return errors.New("Error in creating class: field name is empty")
	} else {
		result.Name = name.(string)
	}

	db.Create(result)

	return nil
}
