package main

import (
	"log"
	"runtime"
	"strconv"

	"gitea.ligthert.net/golang/sudoku-funpark/controller"
	"gitea.ligthert.net/golang/sudoku-funpark/export"
	"gitea.ligthert.net/golang/sudoku-funpark/flags"
	"gitea.ligthert.net/golang/sudoku-funpark/solver"
)

func main() {
	// Instantiate the interfaces
	controller := controller.Controller{}
	export := export.Export{Controller: &controller}
	flags := flags.Flags{Controller: &controller}
	solver := solver.Solver{Controller: &controller}

	// Parse and handle flags
	flags.ParseFlags()

	// Report number of CPUs being used, if set.
	if runtime.NumCPU() != controller.NumCPUs {
		log.Println("Using " + strconv.Itoa(controller.NumCPUs) + " CPUs, (was " + strconv.Itoa(runtime.NumCPU()) + ")")
	}

	// Load blocks from CSV file
	solver.LoadBlocks()

	// Find rows that fit with the entered rows
	solver.PopulateBlocks()

	// If needed, split the workload
	// May exit and throw an error if the work load isn't viable
	if controller.Split != 1 {
		solver.SelectWorkload()
	}

	// Print the total number of solutions to validate
	log.Println("Number of (potential) solutions:", solver.Iter)

	// Check the number of solutions
	go solver.CheckCombinations()
	solver.Tracker()

	log.Println(export.Export())

}
