AWSTemplateFormatVersion: '2010-09-09'
Description: |
  Language Services - Secrets Manager Only
  Use this template to create just the secrets for an existing deployment

Parameters:
  AppName:
    Type: String
    Default: language-services
    Description: Name of the application

  Environment:
    Type: String
    Default: production
    Description: Deployment environment

  OpenAIApiKey:
    Type: String
    NoEcho: true
    Default: ''
    Description: OpenAI API key (optional)

  AuthUsername:
    Type: String
    Default: admin
    Description: Username for application authentication

  AuthPassword:
    Type: String
    NoEcho: true
    Description: Password for application authentication
    MinLength: 8

  LicenseKey:
    Type: String
    NoEcho: true
    Description: License key for the application
    MinLength: 1

  AuthSecret:
    Type: String
    NoEcho: true
    Description: JWT secret for authentication tokens
    MinLength: 16

Resources:
  ApplicationSecrets:
    Type: AWS::SecretsManager::Secret
    Properties:
      Name: !Sub ${AppName}-${Environment}-secrets
      Description: Application secrets for Language Services
      SecretString: !Sub |
        {
          "OPENAI_API_KEY": "${OpenAIApiKey}",
          "USER_NAME": "${AuthUsername}",
          "PASSWORD": "${AuthPassword}",
          "LICENSE_KEY": "${LicenseKey}",
          "AUTH_SECRET": "${AuthSecret}"
        }
      Tags:
        - Key: Name
          Value: !Sub ${AppName}-${Environment}-secrets
        - Key: Application
          Value: !Ref AppName
        - Key: Environment
          Value: !Ref Environment

Outputs:
  SecretsArn:
    Description: Secrets Manager Secret ARN
    Value: !Ref ApplicationSecrets
    Export:
      Name: !Sub ${AppName}-${Environment}-SecretsArn

  SecretsName:
    Description: Secrets Manager Secret Name
    Value: !Sub ${AppName}-${Environment}-secrets
