export interface PayForPressConfig {
	apiKey: string;
	baseUrl?: string;
}

export interface Error {
	success: boolean;
	message: string;
}

export interface User {
	email: string;
	phone?: string;
	id: string;
	metadata?: Record<string, any>;
}

export interface UserUpdate {
	email?: string;
	phone?: string;
	name?: string;
	metadata?: Record<string, any>;
}

export interface UserResponse {
	success: boolean;
	user: User;
	message?: string;
}

export interface SearchParams {
	skip?: number;
	limit?: number;
	value?: string;
	field?: string;
	operator?: '==' | '!=' | '>' | '<' | '>=' | '<=' | '~' | '!~';
	order?: 'asc' | 'desc';
}

export interface Article {
	id: string;
	url: string;
	title?: string;
	author_name?: string;
	price?: number;
	high_value?: boolean;
	org?: string;
	created_at?: string;
	updated_at?: string;
}

export interface ArticleResponse {
	success: boolean;
	article: Article;
	message?: string;
}

export interface ArticlesResponse {
	success: boolean;
	articles: Article[];
	message?: string;
}

export interface ArticleFilters {
	skip?: number;
	limit?: number;
	search?: string;
	sort?: 'created_at' | 'updated_at' | 'title' | 'price';
	order?: 'asc' | 'desc';
}

export interface AppearanceSchema {
	primaryColor?: string;
	theme?: 'dark' | 'light' | 'system';
	large?: boolean;
	borderRadius?: number;
	margin?: number;
	horizontalAlignment?: 'left' | 'center' | 'right';
	verticalAlignment?: 'top' | 'center' | 'bottom';
	inject?: boolean;
	injectSelector?: string;
	injectStyle?: string;
	prepend?: boolean;
	injectDelay?: number;
	backgroundColor?: string;
	paywallMode?: boolean;
	deleteSelector?: string;
}

export interface GraphNode {
	variable:
		| 'time'
		| 'device'
		| 'url'
		| 'referrer'
		| 'country'
		| 'browser'
		| 'loggedIn'
		| 'firstTimeSessions'
		| 'recurringLoadOfArticle'
		| 'visitedUrls'
		| 'highValue'
		| 'elementPresent'
		| 'alreadyPayforPress'
		| 'mobileConnection'
		| 'isp'
		| 'proxy'
		| 'hosting'
		| 'continent';
	matchingType:
		| '='
		| 'startsWith'
		| 'endsWith'
		| 'contains'
		| 'notContains'
		| '!='
		| 'in'
		| 'notIn'
		| '>'
		| '<'
		| '>='
		| '<='
		| 'between'
		| 'notBetween'
		| 'selectorMatches'
		| 'selectorNotMatches'
		| 'regex';
	value:
		| string
		| number
		| boolean
		| string[]
		| {
				hourStart: number;
				minuteStart: number;
				hourEnd: number;
				minuteEnd: number;
		  };
	true: 'showPayForPress' | 'hidePayForPress' | 'excludeUser' | 'default' | 'addCondition';
	false: 'showPayForPress' | 'hidePayForPress' | 'excludeUser' | 'default' | 'addCondition';
	trueNode?: GraphNode;
	falseNode?: GraphNode;
}

export interface TargetingVariable {
	key: string;
	keep?: boolean;
	type?: 'string' | 'number' | 'boolean' | 'array';
	value: any;
	id?: string;
}

export interface TargetingSchema {
	showForAll?: boolean;
	defaultShow?: boolean;
	variables?: TargetingVariable[];
	graph?: GraphNode[];
}

export interface OrganizationDetails {
	allowBuyArticle?: boolean;
	allowHighValueArticlesInPass?: boolean;
	allowHighValueArticlesInSubscription?: boolean;
	allowMonthlyPass?: boolean;
	allowSubscription?: boolean;
	allowTimePass?: boolean;
	blockAds?: boolean;
	discountAfterOne?: number;
	icon?: string;
	keepOriginalNavBar?: boolean;
	logoUrl?: string;
	monthlyPassPrice?: number;
	onboardingStep?: string;
	postPayment?: boolean;
	priceForHighValueArticles?: number;
	pricePerArticle?: number;
	removeSelectors?: string;
	subscriptionPrice?: number;
	timePassLength?: string;
	timePassPrice?: number;
}

export interface SettingsResponse {
	details: OrganizationDetails;
}

export interface Payment {
	id: string;
	amountCents: number;
	article?: string;
	buyer: string;
	expires_at: string;
	renews: boolean;
	transaction_date: string;
	type: 'article' | 'pass' | 'subscription';
}

export interface PaymentResponse {
	success: boolean;
	purchase: Payment;
}

export interface PaymentsResponse {
	success: boolean;
	purchases: Payment[];
}

export interface PaymentCreateParams {
	user_id: string;
	purchase_type: 'article' | 'pass' | 'subscription';
	amountCents: number;
	currency?: 'eur';
	expires_at: string;
}

export interface PaymentSearchParams {
	user_id?: string;
	type?: 'article' | 'pass' | 'subscription';
	before?: string;
	after?: string;
	limit?: number;
	skip?: number;
}
