package dao

import (
	"github.com/sirupsen/logrus"
	"youngee_b_api/app/entity"
)

type LocalLifeMaterialDao struct{}

func (d LocalLifeMaterialDao) DeleteLocalMaterialByLocalId(localId string) error {
	err := Db.Where("local_id = ?", localId).Delete(entity.LocalLifeMaterial{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (d LocalLifeMaterialDao) CreateLocalMaterial(localMaterial entity.LocalLifeMaterial) error {
	err := Db.Create(&localMaterial).Error
	if err != nil {
		return err
	}
	return nil
}

func (d LocalLifeMaterialDao) GetLocalMaterialInfo(localId string) ([]*entity.LocalLifeMaterial, error) {
	var localMaterialInfos []*entity.LocalLifeMaterial
	err := Db.Model(entity.LocalLifeMaterial{}).Where("local_id = ?", localId).Order("created_at asc").Find(&localMaterialInfos).Error
	if err != nil {
		logrus.Errorf("[GetLocalMaterialInfo] error query, err:%+v", err)
		return nil, err
	}
	return localMaterialInfos, nil
}
