package repositories

import (
	"context"

	"github.com/rwadurian/mpc-system/services/account/domain/entities"
	"github.com/rwadurian/mpc-system/services/account/domain/value_objects"
)

// AccountRepository defines the interface for account persistence
type AccountRepository interface {
	// Create creates a new account
	Create(ctx context.Context, account *entities.Account) error

	// GetByID retrieves an account by ID
	GetByID(ctx context.Context, id value_objects.AccountID) (*entities.Account, error)

	// GetByUsername retrieves an account by username
	GetByUsername(ctx context.Context, username string) (*entities.Account, error)

	// GetByEmail retrieves an account by email
	GetByEmail(ctx context.Context, email string) (*entities.Account, error)

	// GetByPublicKey retrieves an account by public key
	GetByPublicKey(ctx context.Context, publicKey []byte) (*entities.Account, error)

	// Update updates an existing account
	Update(ctx context.Context, account *entities.Account) error

	// Delete deletes an account
	Delete(ctx context.Context, id value_objects.AccountID) error

	// ExistsByUsername checks if username exists
	ExistsByUsername(ctx context.Context, username string) (bool, error)

	// ExistsByEmail checks if email exists
	ExistsByEmail(ctx context.Context, email string) (bool, error)

	// List lists accounts with pagination
	List(ctx context.Context, offset, limit int) ([]*entities.Account, error)

	// Count returns the total number of accounts
	Count(ctx context.Context) (int64, error)
}

// AccountShareRepository defines the interface for account share persistence
type AccountShareRepository interface {
	// Create creates a new account share
	Create(ctx context.Context, share *entities.AccountShare) error

	// GetByID retrieves a share by ID
	GetByID(ctx context.Context, id string) (*entities.AccountShare, error)

	// GetByAccountID retrieves all shares for an account
	GetByAccountID(ctx context.Context, accountID value_objects.AccountID) ([]*entities.AccountShare, error)

	// GetActiveByAccountID retrieves active shares for an account
	GetActiveByAccountID(ctx context.Context, accountID value_objects.AccountID) ([]*entities.AccountShare, error)

	// GetByPartyID retrieves shares by party ID
	GetByPartyID(ctx context.Context, partyID string) ([]*entities.AccountShare, error)

	// Update updates a share
	Update(ctx context.Context, share *entities.AccountShare) error

	// Delete deletes a share
	Delete(ctx context.Context, id string) error

	// DeactivateByAccountID deactivates all shares for an account
	DeactivateByAccountID(ctx context.Context, accountID value_objects.AccountID) error

	// DeactivateByShareType deactivates shares of a specific type for an account
	DeactivateByShareType(ctx context.Context, accountID value_objects.AccountID, shareType value_objects.ShareType) error
}

// RecoverySessionRepository defines the interface for recovery session persistence
type RecoverySessionRepository interface {
	// Create creates a new recovery session
	Create(ctx context.Context, session *entities.RecoverySession) error

	// GetByID retrieves a recovery session by ID
	GetByID(ctx context.Context, id string) (*entities.RecoverySession, error)

	// GetByAccountID retrieves recovery sessions for an account
	GetByAccountID(ctx context.Context, accountID value_objects.AccountID) ([]*entities.RecoverySession, error)

	// GetActiveByAccountID retrieves active recovery sessions for an account
	GetActiveByAccountID(ctx context.Context, accountID value_objects.AccountID) (*entities.RecoverySession, error)

	// Update updates a recovery session
	Update(ctx context.Context, session *entities.RecoverySession) error

	// Delete deletes a recovery session
	Delete(ctx context.Context, id string) error
}
