package usecase

import (
	"context"
	"fmt"

	"gitea.computernetthings.ru/yash/crypto_alert_bot/internal/entities"
)

func (uc *Usecase) InstrumentList(ctx context.Context, offset, limit int) ([]entities.Instrument, error) {
	instruments, err := uc.storage.InstrumentList(ctx, offset, limit)
	if err != nil {
		uc.log.Error("failed to list instruments", "offset", offset, "limit", limit, "err", err)
		return nil, fmt.Errorf("failed to list instruments: %w", err)
	}

	return instruments, nil
}

func (uc *Usecase) CreateInstrument(ctx context.Context, instrument *entities.Instrument) (entities.InstrumentID, error) {
	id, err := uc.storage.CreateInstrument(ctx, instrument)
	if err != nil {
		uc.log.Error("failed to create instrument", "instrument", instrument, "err", err)
		return "", fmt.Errorf("failed to create instrument: %w", err)
	}

	return id, nil
}
