import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class AuthService {
  constructor(private readonly configService: ConfigService) {}

  private getSessionToken() {
    return this.configService.get<string>('APP_SESSION_TOKEN') ?? 'phase1-demo-token';
  }

  login(username: string, password: string) {
    const expectedUser =
      this.configService.get<string>('APP_DEMO_USER') ?? 'admin';
    const expectedPassword =
      this.configService.get<string>('APP_DEMO_PASSWORD') ??
      'S3ntAI!Adm1n@2026';

    if (username !== expectedUser || password !== expectedPassword) {
      throw new UnauthorizedException('账号或密码错误');
    }

    return {
      token: this.getSessionToken(),
      user: {
        username,
        displayName: username,
      },
    };
  }
}

