import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { join as pathJoin } from "path";
import { clearNewLine } from "src/common/string";

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

  app() {
    return {
      apiHost: this.configService.get("API_HOST"),
      backOfficeHost: this.configService.get("BO_HOST"),
      appWebHost: this.configService.get("APP_WEB_HOST"),
      appProductHost: this.configService.get("APP_PRODUCT_HOST"),
      appUserHost: this.configService.get("APP_USER_HOST"),
      appNotificationHost: this.configService.get("APP_NOTIFICATION_HOST"),
      appMiscHost: this.configService.get("APP_MISC_HOST"),
      appPaymentHost: this.configService.get("APP_PAYMENT_HOST"),
      appOrderHost: this.configService.get("APP_ORDER_HOST"),
      appCryptoHost: this.configService.get("APP_CRYPTO_HOST"),
      rootDir: pathJoin(__dirname, "../../../"),
    };
  }

  db() {
    return {
      dialect: this.configService.get("DATABASE_DIALECT"),
      host: this.configService.get("DATABASE_HOST"),
      port: this.configService.get("DATABASE_PORT"),
      username: this.configService.get("DATABASE_USERNAME"),
      password: this.configService.get("DATABASE_PASSWORD"),
      database: this.configService.get("DATABASE_NAME"),
      timezone: this.configService.get("DATABASE_TIMEZONE"),
      logging: this.configService.get("DATABASE_LOGGING"),
    };
  }

  jwt() {
    return {
      privateKey: clearNewLine(this.configService.get("JWT_PRIVATE_KEY")),
      publicKey: clearNewLine(this.configService.get("JWT_PUBLIC_KEY")),
      expirationTime: this.configService.get("JWT_EXPIRATION_TIME"),
      accessTokenType: this.configService.get("ACCESS_TOKEN_TYPE"),
    };
  }


  mail() {
    return {
      domain: this.configService.get("MAIL_DOMAIN"),
      api_key: this.configService.get("MAIL_API_KEY"),
      from_name: this.configService.get("MAIL_FROM_NAME"),
      from_email: this.configService.get("MAIL_FROM_ADDRESS"),
    };
  }
}
