export interface Tenant {
	id: string;
	name: string;
	email?: string;
	provider?: 'claude' | 'codex' | null;
	status: 'active' | 'suspended' | 'archived';
	tenant_type?: 'standard' | 'bot';
	discord_category_id?: string;
	discord_role_id?: string;
	discord_invite?: string;
	discord_bot_token?: string;
	discord_user_id?: string;
	discord_pairing_code?: string | null;
	anthropic_key?: string;
	max_concurrent: number;
	max_memory_mb: number;
	cpu_quota: string;
	cpu_weight: number;
	max_disk_mb: number;
	port_range_start?: number;
	port_range_size?: number;
	host_mount?: string;
	is_admin?: number;
	show_progress_messages?: boolean | number;
	credential_id?: string;
	model?: string;
	dashboard_password?: string;
	created_at: string;
	groups?: RegisteredGroup[];
	daily_usage?: DailyUsage;
	resources?: {
		containers: Array<{ name: string; status: string; kind?: 'agent' | 'app' }>;
		container_count: number;
		volume?: { used_mb: number; avail_mb: number };
		slice_mem_mb?: number;
	};
}

export interface RegisteredGroup {
	jid: string;
	name: string;
	folder: string;
	trigger_pattern?: string;
	requires_trigger?: number;
	is_main?: number;
	tenant_id?: string;
	hooks_token?: string | null;
	hooks_enabled?: number;
}

export interface DailyUsage {
	requests: number;
	duration_ms: number;
	input_tokens: number;
	output_tokens: number;
	cache_creation_tokens?: number;
	cache_read_tokens?: number;
	limit_requests?: number;
	limit_duration_ms?: number;
}

export interface SystemStats {
	hostname: string;
	uptime_hours: number;
	cpu_cores: number;
	cpu_model: string;
	load_avg: number[];
	mem_total_gb: number;
	mem_used_gb: number;
	mem_free_gb: number;
	mem_percent: number;
	disk_total_gb: number;
	disk_used_gb: number;
	disk_free_gb: number;
	disk_percent: number;
	container_image: string;
	platform: string;
	tenant_count: number;
	service_status: string;
	service_memory_mb: number;
	db?: {
		file_mb: number;
		wal_mb: number;
		shm_kb: number;
		page_count: number;
		page_size: number;
		freelist_count: number;
		messages: number;
		usage_log: number;
		chats: number;
		tenants: number;
	};
}

export interface MemoryInfo {
	host_total_mb: number;
	host_used_mb: number;
	host_free_mb: number;
	system_mb: number;
	nanoclaw_mb: number;
	tenants: TenantMemory[];
}

export interface TenantMemory {
	id: string;
	current_mb: number;
	limit_mb: number;
}

export interface DiskInfo {
	host_total_gb: number;
	tenants: TenantDisk[];
}

export interface TenantDisk {
	id: string;
	allocated_mb: number;
	actual_mb: number;
	used_mb: number;
	avail_mb: number;
	limit_mb: number;
}

export interface UsageData {
	totals: UsageTenantTotal[];
	daily: UsageDayEntry[];
	channels: UsageChannel[];
}

export interface UsageTenantTotal {
	tenant_id: string;
	requests: number;
	duration_ms: number;
	input_tokens: number;
	output_tokens: number;
	cache_creation_tokens: number;
	cache_read_tokens: number;
}

export interface UsageDayEntry {
	date: string;
	tenant_id: string;
	requests: number;
	duration_ms: number;
	input_tokens: number;
	output_tokens: number;
}

export interface UsageChannel {
	group_folder: string;
	tenant_id: string;
	requests: number;
	duration_ms: number;
}

export interface Credential {
	id: string;
	provider?: 'claude' | 'codex' | 'pi' | null;
	pi_backend?: string | null;
	type: 'oauth' | 'apikey';
	label?: string;
	status: string;
	access_token?: string;
	api_key?: string;
	expires_at?: string;
	plan_type?: string;
	rate_limit_tier?: string;
	last_used_at?: string;
	total_requests?: number;
	error_message?: string;
	created_at: string;
	account_id?: string | null;
}

export interface Task {
	id: string;
	title: string;
	description?: string;
	status: 'backlog' | 'todo' | 'in_progress' | 'in_review' | 'done';
	priority: 'low' | 'normal' | 'high' | 'urgent';
	assigned_to?: string;
	labels: string[];
	comments: TaskComment[];
	created_at: string;
	updated_at: string;
}

export interface TaskComment {
	id: string;
	author: string;
	content: string;
	created_at: string;
}

export interface CustomDomain {
	id: string;
	tenant_id: string;
	domain: string;
	target: string;
	verification_token: string;
	status: 'pending' | 'active' | 'failed';
	created_at: string;
	verified_at: string | null;
}

export interface Skill {
	id: string;
	name: string;
	description: string;
	source: 'base' | 'tenant';
	content?: string;
}

export interface Agent {
	id: string;
	name: string;
	description: string;
	model?: string;
	max_turns?: number;
	allowed_tools?: string;
	source: 'base' | 'tenant';
	content?: string;
}

export interface Project {
	id: string;
	name: string;
	description?: string;
	status: 'planning' | 'active' | 'paused' | 'completed' | 'archived';
	folder?: string;
	created_at: string;
	updated_at: string;
}

export interface TenantInfo {
	id: string;
	name: string;
	email?: string;
	status: string;
	created_at: string;
	discord_invite?: string;
	groups: RegisteredGroup[];
	resources: {
		memory_mb: number;
		memory_limit_mb: number;
		disk_mb: number;
		disk_limit_mb: number;
		containers_running: number;
		containers_max: number;
		cpu_quota: string;
		cpu_weight: number;
	};
}

export type ToastType = 'success' | 'error' | 'info';

export interface Toast {
	id: string;
	type: ToastType;
	message: string;
}

export interface GlobalSettings {
	default_provider: string;
	default_model: string;
	concierge_bot_user_id: string;
	concierge_tenant_id: string;
}
