# Copyright (c) DevSecCode. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root.

"""Pydantic models for secrets / environment variable management."""

from __future__ import annotations

from enum import Enum
from typing import Optional

from pydantic import BaseModel, Field


class SecretEnvironment(str, Enum):
	"""Deployment environment scoping for secrets."""
	dev = "dev"
	staging = "staging"
	prod = "prod"


class SecretEntry(BaseModel):
	"""A single secret key-value pair."""
	key: str = Field(..., min_length=1, description="Environment variable name")
	value: str = Field(..., description="Secret value (encrypted at rest)")
	environment: SecretEnvironment = Field(default=SecretEnvironment.dev, description="Target environment")
	description: Optional[str] = Field(default=None, description="Optional human-readable description")


class SetSecretRequest(BaseModel):
	"""Request body for creating or updating a secret."""
	key: str = Field(..., min_length=1)
	value: str
	environment: SecretEnvironment = SecretEnvironment.dev
	description: Optional[str] = None
	master_password: str = Field(..., description="Vault master password")


class DeleteSecretRequest(BaseModel):
	"""Request body for deleting a secret."""
	master_password: str


class SyncEnvRequest(BaseModel):
	"""Request to sync secrets to a .env file."""
	environment: SecretEnvironment = SecretEnvironment.dev
	master_password: str
	target_path: Optional[str] = Field(default=None, description="Custom .env file path (relative to workspace)")


class SecretKeyInfo(BaseModel):
	"""Metadata about a stored secret (value excluded)."""
	key: str
	environment: SecretEnvironment
	description: Optional[str] = None
	has_value: bool = True
