package user

import (
	userDao "eta/eta_mini_ht_api/models/user"
)

type MetaInfoDTO struct {
	Id         int    `json:"id"`
	Uid        string `json:"Uid,omitempty"`
	Meta       string `json:"Meta,omitempty"`
	From       string `json:"From,omitempty"`
	To         string `json:"To,omitempty"`
	SourceType string `json:"SourceType,omitempty"`
	MetaType   string `json:"MetaType,omitempty"`
}

type MetaData struct {
	SourceId      int    `json:"reportId"`
	AuthorId      int    `json:"AuthorId"`
	AuthorName    string `json:"authorName"`
	PublishedTime string `json:"publishedTime"`
}

func CreateMetaInfo(dto MetaInfoDTO) (err error) {
	return userDao.CreateMetaInfo(convertToMetaInfo(dto))
}
func convertToMetaInfo(dto MetaInfoDTO) userDao.MetaInfo {
	return userDao.MetaInfo{
		Uid:        dto.Uid,
		Meta:       dto.Meta,
		From:       dto.From,
		To:         dto.To,
		SourceType: userDao.SourceType(dto.SourceType),
		MetaType:   userDao.MetaType(dto.MetaType),
	}
}
func convertToMetaDTO(dto userDao.MetaInfo) MetaInfoDTO {
	return MetaInfoDTO{
		Id:         dto.Id,
		Uid:        dto.Uid,
		Meta:       dto.Meta,
		From:       dto.From,
		To:         dto.To,
		SourceType: string(dto.SourceType),
		MetaType:   string(dto.MetaType),
	}
}

func GetInitMetaInfos() (list []MetaInfoDTO) {
	metas := userDao.GetInitMetaInfos()
	for _, meta := range metas {
		list = append(list, convertToMetaDTO(meta))
	}
	return
}

func PendingMetaInfo(id int) bool {
	return userDao.PendingMetaInfo(id)
}
