package service

import (
	"fmt"

	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/log"
	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/recconf"
	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/service/recall"
)

type Category struct {
	CategoryName string
	recalls      []recall.Recall
	recallNames  []string
}

func NewCategory(name string) *Category {
	c := Category{CategoryName: name}
	c.recalls = make([]recall.Recall, 0)
	c.recallNames = make([]string, 0)
	return &c
}

func (c *Category) Init(config recconf.CategoryConfig) {
	for _, recallName := range config.RecallNames {
		recall, err := recall.GetRecall(recallName)
		if err != nil {
			log.Error(fmt.Sprintf("module=category init\terror=%v", err))
			continue
		}

		c.recalls = append(c.recalls, recall)
		c.recallNames = append(c.recallNames, recallName)
	}
}

func (c *Category) GetRecalls() []recall.Recall {
	return c.recalls
}

func (c *Category) GetRecallNames() []string {
	return c.recallNames
}
