// 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;
	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;
	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;
	created_at: string;
	updated_at: string;
}

export interface Settings {
	domain: string;
	server_ip: string;
	network: string;
	subdomain_pattern: string;
	notification_url: string;
	npm_url: string;
	npm_email: string;
	npm_password: string;
	webhook_secret: string;
	polling_interval: string;
	updated_at: 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;
}

/** Volume mount configuration for a project. */
export interface Volume {
	id: string;
	project_id: string;
	source: string;
	target: string;
	mode: 'shared' | 'isolated';
	created_at: string;
	updated_at: string;
}
