package media

import (
	"eta/eta_mini_ht_api/models"
	"time"
)

type ImageSource struct {
	Id           int       `gorm:"column:id;primary_key;autoIncrement:'id'"`
	ImgName      string    `gorm:"column:img_name"`
	SrcUrl       string    `gorm:"column:src_url"`
	PermissionId int       `gorm:"column:permission_id"`
	Deleted      bool      `gorm:"deleted"`
	CreatedTime  time.Time `gorm:"column:created_time"`
	UpdatedTime  time.Time `gorm:"column:updated_time"`
}

func (i *ImageSource) TableName() string {
	return "image_sources"
}

func GetIdsByPermissionId(permissionId int) (ids []int, err error) {
	db := models.Main()
	err = db.Model(&ImageSource{}).Select("id").Where("permission_id = ? and deleted = 0", permissionId).Scan(&ids).Error
	return
}

func GetImageSrc(id int) (src string, err error) {
	db := models.Main()
	err = db.Model(&ImageSource{}).Select("src_url").Where("id = ?", id).Scan(&src).Error
	return
}
