package marketplace

import (
	"context"
	"sipro-mps/internal/marketplace/db"
)

type dbRepository struct {
	conn db.DBTX
}

func NewDBRepository(conn db.DBTX) Repository {
	return &dbRepository{conn: conn}
}

func (r *dbRepository) GetMarketplaceByID(ctx context.Context, id int) (*Marketplace, error) {
	queries := db.New(r.conn)
	marketplace, err := queries.GetMarketplaceByID(ctx, int32(id))
	if err != nil {
		return nil, err
	}
	return &Marketplace{
		ID:              int(marketplace.ID),
		BaseMarketplace: int(marketplace.BaseMarketplace),
		AuthData:        marketplace.AuthData.String,
		WarehouseID:     marketplace.WarehouseID.String,
		AuthDataJson:    marketplace.AuthDataJson,
		CampaignID:      marketplace.CampaignID.String,
	}, nil
}
