package dao

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

type ProjectBriefDao struct{}

func (p ProjectBriefDao) DeleteSecBriefBySelectionId(projectId string) error {
	err := Db.Where("project_id = ?", projectId).Delete(entity.ProjectBrief{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (p ProjectBriefDao) CreateProjectBrief(briefInfo entity.ProjectBrief) error {
	err := Db.Create(&briefInfo).Error
	if err != nil {
		return err
	}
	return nil
}

func (p ProjectBriefDao) GetProjectBriefInfo(projectId string) ([]*entity.ProjectBrief, error) {
	var projectBriefInfos []*entity.ProjectBrief
	err := Db.Model(entity.ProjectBrief{}).Where("project_id = ?", projectId).Order("created_at asc").Find(&projectBriefInfos).Error
	if err != nil {
		logrus.Errorf("[GetProjectBriefInfo] error query mysql, err:%+v", err)
		return nil, err
	}
	return projectBriefInfos, nil
}
