// Types matching the Go backend store models (internal/store/models.go).

export interface Project {
	id: string;
	name: string;
	registry: string;
	image: string;
	port: number;
	healthcheck: string;
	env: string;
	volumes: string;
	created_at: string;
	updated_at: string;
}

export interface Stage {
	id: string;
	project_id: string;
	name: string;
	tag_pattern: string;
	auto_deploy: boolean;
	max_instances: number;
	confirm: boolean;
	enable_proxy: boolean;
	promote_from: string;
	subdomain: string;
	created_at: string;
	updated_at: string;
}

export interface Instance {
	id: string;
	stage_id: string;
	project_id: string;
	container_id: string;
	image_tag: string;
	subdomain: string;
	npm_proxy_id: number;
	status: InstanceStatus;
	port: number;
	last_alive_at?: string;
	created_at: string;
	updated_at: string;
}

export type InstanceStatus = 'running' | 'stopped' | 'failed' | 'removing';

export interface Deploy {
	id: string;
	project_id: string;
	stage_id: string;
	instance_id: string;
	image_tag: string;
	status: DeployStatus;
	started_at: string;
	finished_at: string;
	error: string;
}

export type DeployStatus =
	| 'pending'
	| 'pulling'
	| 'starting'
	| 'configuring_proxy'
	| 'health_checking'
	| 'success'
	| 'failed'
	| 'rolled_back';

export interface DeployLog {
	id: number;
	deploy_id: string;
	message: string;
	level: 'info' | 'warn' | 'error';
	created_at: string;
}

export interface Registry {
	id: string;
	name: string;
	url: string;
	type: string;
	token: string;
	owner: string;
	has_token?: boolean;
	created_at: string;
	updated_at: string;
}

/** A container image discovered from a registry. */
export interface RegistryImage {
	name: string;
	owner: string;
	full_ref: string;
}

export interface Settings {
	domain: string;
	server_ip: string;
	network: string;
	subdomain_pattern: string;
	notification_url: string;
	npm_url: string;
	npm_email: string;
	/** Returned by GET as a boolean indicating whether the password is set. */
	has_npm_password: boolean;
	/** Sent on PUT to update the password; never returned by GET. */
	npm_password?: string;
	polling_interval: string;
	base_volume_path: string;
	ssl_certificate_id: number;
	stale_threshold_days: number;
	allowed_volume_paths: string;
	wildcard_dns: boolean;
	dns_provider: string;
	has_cloudflare_api_token: boolean;
	cloudflare_zone_id: string;
	proxy_provider: string;
	traefik_entrypoint: string;
	traefik_cert_resolver: string;
	traefik_network: string;
	traefik_api_url: string;
	backup_enabled: boolean;
	backup_interval_hours: number;
	backup_retention_count: number;
	updated_at: string;
}

/** A DNS zone from a provider (e.g., Cloudflare). */
export interface DnsZone {
	id: string;
	name: string;
}

/** A DNS record view for the DNS Records page. */
export interface DnsRecordView {
	fqdn: string;
	type: string;
	content: string;
	consumer_type: string;
	consumer_name: string;
	consumer_id: string;
	status: string;
}

/** A backup metadata record. */
export interface BackupInfo {
	id: string;
	filename: string;
	size_bytes: number;
	backup_type: string;
	created_at: string;
}

/** An SSL certificate from Nginx Proxy Manager. */
export interface NpmCertificate {
	id: number;
	nice_name: string;
	domain_names: string[];
	expires_on: string;
	provider: string;
}

/** Standard API envelope returned by all backend endpoints. */
export interface ApiEnvelope<T> {
	success: boolean;
	data?: T;
	error?: string;
}

/** Response shape for GET /api/projects/:id */
export interface ProjectDetail {
	project: Project;
	stages: Stage[];
}

/** Response shape for POST /api/deploy/inspect */
export interface InspectResult {
	image: string;
	port: number;
	healthcheck: string;
}

/** Stage environment variable override. */
export interface StageEnv {
	id: string;
	stage_id: string;
	key: string;
	value: string;
	encrypted: boolean;
	created_at: string;
	updated_at: string;
}

/** Item for the EntityPicker command-palette component. */
export interface EntityPickerItem {
	value: string;
	label: string;
	description?: string;
	icon?: string;
	group?: string;
	disabled?: boolean;
	disabledHint?: string;
}

/** Volume scope determines the sharing level. */
export type VolumeScope = 'instance' | 'stage' | 'project' | 'project_named' | 'named' | 'ephemeral' | 'absolute';

/** Volume mount configuration for a project. */
export interface Volume {
	id: string;
	project_id: string;
	source: string;
	target: string;
	mode?: string;
	scope: VolumeScope;
	name: string;
	created_at: string;
	updated_at: string;
}

/** Scope metadata returned by GET /api/volumes/scopes. */
export interface VolumeScopeInfo {
	scope: VolumeScope;
	description: string;
	needs_name: boolean;
	path_example: string;
}

/** A file or directory entry in a volume listing. */
export interface FileEntry {
	name: string;
	is_dir: boolean;
	size: number;
	mod_time: string;
}

/** Response from the volume browse endpoint. */
export interface BrowseResult {
	path: string;
	entries: FileEntry[];
}

/** Docker daemon health check result. */
export interface DockerHealth {
	connected: boolean;
	error?: string;
	category?: string;
	hints?: string[];
	platform?: string;
	checked_at?: string;
}

export interface ProxyHealth {
	connected: boolean;
	provider: string;
	error?: string;
}

/** A proxy route managed by a deployed instance. */
export interface ProxyRoute {
	instance_id: string;
	project_id: string;
	project_name: string;
	stage_id: string;
	stage_name: string;
	image_tag: string;
	subdomain: string;
	domain: string;
	container_id: string;
	port: number;
	proxy_route_id: string;
	npm_proxy_id: number;
	status: string;
	created_at: string;
}

/** A persistent event log entry. */
export interface EventLogEntry {
	id: number;
	source: string;
	severity: 'info' | 'warn' | 'error';
	message: string;
	metadata: string;
	created_at: string;
}

/** Severity counts for the event log. */
export interface EventLogStats {
	info: number;
	warn: number;
	error: number;
	total: number;
}

/** A container detected as stale by the backend poller. */
export interface StaleContainer {
	instance: {
		id: string;
		stage_id: string;
		project_id: string;
		container_id: string;
		image_tag: string;
		subdomain: string;
		npm_proxy_id: number;
		status: string;
		port: number;
		last_alive_at: string;
		created_at: string;
		updated_at: string;
	};
	project_name: string;
	stage_name: string;
	days_stale: number;
}

/** Container CPU and memory stats from the Docker stats API. */
export interface ContainerStats {
	cpu_percent: number;
	memory_usage: number;
	memory_limit: number;
	memory_percent: number;
}

