package user

import (
	"bindbox-game/internal/pkg/logger"
	"bindbox-game/internal/repository/mysql"
	"bindbox-game/internal/repository/mysql/dao"
	"bindbox-game/internal/repository/mysql/model"
	"context"
	"time"
)

type Service interface {
	UpdateProfile(ctx context.Context, userID int64, nickname *string, avatar *string) (*model.Users, error)
	ListOrders(ctx context.Context, userID int64, page, pageSize int) (items []*model.Orders, total int64, err error)
	ListOrdersWithItems(ctx context.Context, userID int64, page, pageSize int) (items []*OrderWithItems, total int64, err error)
	ListInventoryWithProduct(ctx context.Context, userID int64, page, pageSize int) (items []*InventoryWithProduct, total int64, err error)
	ListCoupons(ctx context.Context, userID int64, page, pageSize int) (items []*model.UserCoupons, total int64, err error)
	ListPointsLedger(ctx context.Context, userID int64, page, pageSize int) (items []*model.UserPointsLedger, total int64, err error)
	GetPointsBalance(ctx context.Context, userID int64) (int64, error)
	LoginWeixin(ctx context.Context, in LoginWeixinInput) (*model.Users, error)
	ListInvites(ctx context.Context, userID int64, page, pageSize int) (items []*model.Users, total int64, err error)
	AddPoints(ctx context.Context, userID int64, points int64, kind string, remark string, validStart *time.Time, validEnd *time.Time) error
	AddCoupon(ctx context.Context, userID int64, couponID int64) error
	GrantReward(ctx context.Context, userID int64, req GrantRewardRequest) (*GrantRewardResponse, error)
    AddItemCard(ctx context.Context, userID int64, cardID int64, quantity int) error
    ListUserItemCards(ctx context.Context, userID int64, page, pageSize int) (items []*model.UserItemCards, total int64, err error)
    ListUserItemCardsWithTemplate(ctx context.Context, userID int64, page, pageSize int) (items []*ItemCardWithTemplate, total int64, err error)
    ListUserItemCardUses(ctx context.Context, userID int64, page, pageSize int) (items []*model.ActivityDrawEffects, total int64, err error)
    GetUserStats(ctx context.Context, userID int64) (*UserStats, error)
    AddAddress(ctx context.Context, userID int64, in AddAddressInput) (*model.UserAddresses, error)
    ListAddresses(ctx context.Context, userID int64, page, pageSize int) (items []*model.UserAddresses, total int64, err error)
    SetDefaultAddress(ctx context.Context, userID int64, addressID int64) error
    DeleteAddress(ctx context.Context, userID int64, addressID int64) error
}

type service struct {
	logger  logger.CustomLogger
	readDB  *dao.Query
	writeDB *dao.Query
}

func New(l logger.CustomLogger, db mysql.Repo) Service {
	return &service{logger: l, readDB: dao.Use(db.GetDbR()), writeDB: dao.Use(db.GetDbW())}
}
