package domain

import "context"

// Repository persists accounts + oauth states.
type Repository interface {
	Insert(ctx context.Context, a *Account) error
	Update(ctx context.Context, a *Account) error
	FindByID(ctx context.Context, id string) (*Account, error)
	// FindByOwnerAndThreadsUser returns existing binding for reconnect upsert.
	FindByOwnerAndThreadsUser(ctx context.Context, ownerUID int64, threadsUserID string) (*Account, error)
	ListByOwner(ctx context.Context, ownerUID int64) ([]*Account, error)
	Delete(ctx context.Context, id string) error

	SaveState(ctx context.Context, st *OAuthState) error
	TakeState(ctx context.Context, state string) (*OAuthState, error) // consume once
}

// Provider abstracts Meta / fake OAuth.
type Provider interface {
	// Name for logs
	Name() string
	// AuthorizeURL builds browser redirect URL for given state.
	AuthorizeURL(state, redirectURI string) string
	// ExchangeCode trades code for tokens + profile.
	ExchangeCode(ctx context.Context, code, redirectURI string) (*TokenPair, error)
	// Refresh extends session.
	Refresh(ctx context.Context, refreshToken string) (*TokenPair, error)
}
