package admin

import (
	"context"
	"time"

	"github.com/gofiber/fiber/v2"
	"github.com/golang-jwt/jwt/v4"

	"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/model"
)

type (
	CacheService interface {
		Delete(key string)
	}

	TransactionManager interface {
		ReadCommitted(context.Context, func(ctx context.Context) error) error
	}

	ArticleRepository interface {
		GetAll(ctx context.Context) ([]model.Article, error)
		GetByURL(ctx context.Context, url string, lang model.LanguageID) (*model.Article, error)
		GetByID(ctx context.Context, id uint64) (*model.Article, error)
		Add(ctx context.Context, m model.Article) (uint64, error)
		Update(ctx context.Context, m model.Article) error
		Delete(ctx context.Context, id uint64) error
	}

	TagRepository interface {
		GetAll(ctx context.Context) ([]model.Tag, error)
		IsUsed(ctx context.Context, id uint64) (bool, error)
		GetByArticleID(ctx context.Context, id uint64) ([]model.Tag, error)
		GetByURL(ctx context.Context, tag string) (*model.Tag, error)
		GetByID(ctx context.Context, id uint64) (*model.Tag, error)
		Add(ctx context.Context, m model.Tag) error
		Update(ctx context.Context, m model.Tag) error
		Delete(ctx context.Context, id uint64) error
	}

	ArticleTagRepository interface {
		Add(ctx context.Context, id uint64, tagIDs []uint64) error
		Delete(ctx context.Context, id uint64, tagIDs []uint64) error
		DeleteByArticleID(ctx context.Context, id uint64) error
	}

	LanguageRepository interface {
		GetAll(ctx context.Context) ([]model.Language, error)
	}

	AuthService interface {
		GeneratePasswordHash(password string) (string, error)
		IsCorrectPassword(password string, hash string) bool
		GenerateToken(user model.User) (string, error)
		GetClaims(fctx *fiber.Ctx) jwt.MapClaims
	}

	ConfigService interface {
		JWTCookie() string
		JWTLifeTime() time.Duration
	}

	UserRepository interface {
		Get(ctx context.Context, username string) (*model.User, error)
		Add(ctx context.Context, username string, password string) (uint64, error)
		UpdatePassword(ctx context.Context, id uint64, newPassword string) error
	}
)
