package dao

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

type ProjectMaterialDao struct{}

func (d ProjectMaterialDao) DeleteProjectMaterialByProjectId(projectId string) error {
	err := Db.Where("project_id = ?", projectId).Delete(entity.ProjectMaterial{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (d ProjectMaterialDao) CreateProjectMaterial(projectMaterial entity.ProjectMaterial) error {
	err := Db.Create(&projectMaterial).Error
	if err != nil {
		return err
	}
	return nil
}

func (d ProjectMaterialDao) GetProjectMaterialInfo(projectId string) ([]*entity.ProjectMaterial, error) {
	var projectMaterialInfos []*entity.ProjectMaterial
	err := Db.Model(entity.ProjectMaterial{}).Where("project_id = ?", projectId).Order("created_at asc").Find(&projectMaterialInfos).Error
	if err != nil {
		logrus.Errorf("[GetProjectMaterialInfo] error query, err:%+v", err)
		return nil, err
	}
	return projectMaterialInfos, nil
}
