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

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

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

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

    return {
      token: 'phase1-demo-token',
      user: {
        username,
        displayName: '阶段 1 演示账号',
      },
    };
  }
}
