package dao

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

type RecruitStrategyDao struct{}

func (d RecruitStrategyDao) DeleteRecruitStrategyByProjectID(projectId string) error {
	err := Db.Where("project_id = ?", projectId).Delete(&entity.RecruitStrategy{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (d RecruitStrategyDao) CreateRecruitStrategy(recruitStrategys []entity.RecruitStrategy) error {
	err := Db.Create(&recruitStrategys).Error
	if err != nil {
		return err
	}
	return nil
}

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