package main

import (
	"log/slog"

	"github.com/maximotejeda/us_dop_scrapper/config"
	"github.com/maximotejeda/us_dop_scrapper/internal/adapters/crawler"
	dl "github.com/maximotejeda/us_dop_scrapper/internal/adapters/dolar"
	"github.com/maximotejeda/us_dop_scrapper/internal/application/core/api"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	log := slog.Default()
	var opts []grpc.DialOption
	opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
	conn, err := grpc.Dial(config.GetDollarServiceURL(), opts...)

	if err != nil {
		log.Error("creating gerpc conn", "error", err)
		panic(err)
	}
	defer conn.Close()
	dol, err := dl.NewAdapter(conn)
	if err != nil {
		log.Error("creating service adapter", "error", err)
		panic(err)
	}
	crawler, err := crawler.Selector(config.GetWho(), dol)
	if err != nil {
		log.Error("selecting crawler  adapter", "error", err)
		panic(err)
	}
	app := api.NewApplication(crawler, dol)
	app.Run()
}
