package dao

import "server/global"

type NecessaryDocument struct {
	global.GVA_MODEL
	FileGenreId int    `json:"fileGenreId" form:"fileGenreId" gorm:"comment:所属文件类型"`
	Name        string `json:"name" form:"name" gorm:"comment:必要文件名"`
}

func (NecessaryDocument) TableName() string {
	return "necessary_document"
}

func QueryNecessaryDocuments() (necessaryDocuments []NecessaryDocument, err error) {
	err = global.GVA_DB.Find(&necessaryDocuments).Error
	return necessaryDocuments, err
}

func QueryNecessaryDocumentByGenreId(id int) (necessaryDocuments []NecessaryDocument, err error) {
	err = global.GVA_DB.Model(&NecessaryDocument{}).Where("file_genre_id =?", id).Find(&necessaryDocuments).Error
	return necessaryDocuments, err
}

func (n NecessaryDocument) CreateNecessaryDocument() error {
	err := global.GVA_DB.Create(&n).Error
	return err
}

func (n NecessaryDocument) UpdateNecessaryDocument() error {
	err := global.GVA_DB.Save(&n).Error
	return err
}

func (n NecessaryDocument) DeleteNecessaryDocument() error {
	err := global.GVA_DB.Unscoped().Delete(&n).Error
	return err
}
