package types

import (
	"encoding/json"
	"github.com/hibiken/asynq"
	"time"
)

type FetchProductsTask struct {
	MarketplaceId int
}

func (t *FetchProductsTask) Unmarshal(task *asynq.Task) error {
	return json.Unmarshal(task.Payload(), t)

}

func NewFetchProductsTask(taskType string, marketplaceId int) (*asynq.Task, error) {
	payload, err := json.Marshal(&FetchProductsTask{MarketplaceId: marketplaceId})
	if err != nil {
		return nil, err
	}
	return asynq.NewTask(taskType, payload, asynq.MaxRetry(2), asynq.Timeout(20*time.Minute)), nil
}
