type Verdict = 'new' | 'working' | 'moved' | 'broken' | 'blocked' | 'retrying';

type Reason =
	| 'ok'
	| 'redirect'
	| 'not_found'
	| 'gone'
	| 'no_host'
	| 'trashed'
	| 'server_error'
	| 'timeout'
	| 'ssl'
	| 'forbidden'
	| 'login'
	| 'rate_limited';

type LinkKind = 'link' | 'image' | 'embed';

export type LinkStatusFilter =
	'problems' | 'broken' | 'blocked' | 'moved' | 'working' | 'ignored';

export type Link = {
	id: number;
	url: string;
	host: string;
	kind: LinkKind;
	internal: boolean;
	verdict: Verdict;
	reason: Reason;
	ignored: boolean;
	http_code: number | null;
	final_url: string | null;
	streak: number;
	since: string | null;
	checked_at: string | null;
	uses_count: number;
};

type LinkUse = {
	post_id: number;
	post_title: string;
	post_type_label: string;
	edit_url: string | null;
	view_url: string | null;
	builder: string | null;
	text: string;
	before: string;
	after: string;
};

export type LinkDetail = {
	uses: LinkUse[];
	suggested_url: string | null;
} & Link;

export type SuggestionKind = 'closest_page' | 'site_home' | 'archive';

export type Suggestion = {
	kind: SuggestionKind;
	url: string;
};

export type LinksQuery = {
	status: LinkStatusFilter;
	search?: string;
	orderby?: 'priority' | 'uses' | 'checked_at' | 'url';
	order?: 'asc' | 'desc';
	page?: number;
	per_page: number;
};

export type LinksPage = {
	items: Link[];
	total: number;
};

export type CheckResult = {
	verdict: Verdict;
	reason: Reason;
	http_code: number | null;
	final_url: string | null;
};
