package media

import (
	"eta/eta_mini_ht_api/models"
)

// MediaPermissionMapping 表示媒体权限映射
type MediaPermissionMapping struct {
	ID           int       `gorm:"primaryKey;autoIncrement;column:id"` // 主键
	PermissionID int       `gorm:"column:permission_id;not null"`      // 权限 ID
	MediaID      int       `gorm:"column:media_id;not null"`           // 媒体 ID
	MediaType    MediaType `gorm:"column:media_type;not null"`         // 媒体类型
}

func GetMediaPermissionMappingByPermissionId(mediaType string, permissionIds []int) (mediaIds []int, err error) {
	db := models.Main()
	err = db.Model(&MediaPermissionMapping{}).Select("DISTINCT media_id").Where("media_type = ? and deleted =? and permission_id in ?", mediaType, false, permissionIds).Scan(&mediaIds).Error
	return
}
func InsertMediaPermissionMapping(mediaType MediaPermissionMapping) {
	db := models.Main()
	_ = db.Create(&mediaType).Error
	return
}