module PublishHelperBot.Environment

open System
open System.IO
open Newtonsoft.Json
open Serilog

[<RequireQualifiedAccess>]
module Logging =
    let logger =
        let config = LoggerConfiguration()
        config.WriteTo.Console().CreateLogger()

type public BotConfig = {
    token: string
    relayUrl: string
    chanelId: int64
    adminChatId: int64
    YoutubeDlUrl: string
}

let private readConfig =
    File.ReadAllText >> JsonConvert.DeserializeObject<BotConfig>

let public createConfig (name: string) =
    match Environment.GetEnvironmentVariable(name) with
    | null ->
          Logging.logger.Error("Missing env")
          ApplicationException("Missing config path env") |> raise
    | path ->
          Logging.logger.Information("Read config from env")
          readConfig path