/*
 * Copyright 2026 Oleg Borodin <onborodin@gmail.com>
 */
package imageoper

import (
	"context"
	"fmt"
	"net/http"

	"mstore/pkg/descr"
)

type GetTagsParams struct {
	Name string
}
type GetTagsResult struct {
	TagDescr descr.Tags
}

func (oper *Operator) GetTags(ctx context.Context, params *GetTagsParams) (*GetTagsResult, int, error) {
	var err error
	res := &GetTagsResult{
		TagDescr: descr.Tags{
			Name: params.Name,
			Tags: make([]string, 0),
		},
	}

	if params.Name == "" {
		err = fmt.Errorf("Empty name")
		return res, http.StatusBadRequest, err
	}
	manifestDescrs, err := oper.mdb.ListManifestsByName(ctx, params.Name)
	if err != nil {
		return res, http.StatusInternalServerError, err
	}
	for _, manifestDescr := range manifestDescrs {
		res.TagDescr.Tags = append(res.TagDescr.Tags, manifestDescr.Reference)
	}
	return res, http.StatusOK, err
}
